//############################## [CMS PORTAL] - JAVA SCRIPTS
//### ver. 1.52 [2009-10-14]
//###
//### Copyright by CN Design Marcin Czechowski
//###
//### cndesign.pl   biuro@cndesign.pl
//###
//### All rights reserved.
//############################################



//************************* Wyskakujace okno

function displayWindow(url, width, height)
{
 var Win = window.open(url,"displayWindow",'width=' + width + ',height=' + height + ',resizable=0,scrollbars=yes,menubar=no' );
}



//************************* Liczenie znakow i ograniczenie textarea
// <span id=x>300</span><textarea onKeyUp=\"char_left(this,299);\" OnMouseOver=\"char_left(this,299);\">

function char_left(pole,max)
{
 document.getElementById('x').innerHTML = max - pole.value.length;
 if (pole.value.length > max) pole.value = pole.value.substr(0,max);
}



//************************* Podmiana duzego zdjecia

function swap_image(image)
{
 document.getElementById('big_image').innerHTML = "<img src=" + image + " alt='' border=0>";
}



//************************* Zwiększanie i zmniejszanie wartości w poli input o 1

function plus_minus(pole,act)
{
 var p = document.getElementById(pole);
 var p_show = document.getElementById(pole + '_show').firstChild;

 if ( act == 'plus' )
 {
  p_show.nodeValue++;
 }
 else if ( act == 'minus' )
 {
  if ( p_show.nodeValue > 1 ) p_show.nodeValue--;
 }
 
 p.value = p_show.nodeValue;
}



//*************************************************************************************
//************************* EFEKTY POKAZYWANIA I UKTYWANIA ELEMENTÓW

//*** SHOW / HIDE

var show_hide_opened = 0;
function show_hide(id, speed)
{
 if(!speed) var speed = "normal";

 if(show_hide_opened == 0)
 {
  $('#pos_' + id).show(speed);
  show_hide_opened = id;
 }
 else if(show_hide_opened != 0)
 {
  if(id == show_hide_opened)
  {
   $('#pos_' + id).hide(speed);
   show_hide_opened = 0;
  }
  else if (id != show_hide_opened)
  {
   $('#pos_' + show_hide_opened).hide(speed);
   $('#pos_' + id).show(speed);
   show_hide_opened = id;
  }
 }
}



//*** FADE IN / FADE OUT

var fadein_fadeout_opened = 0;
function fadein_fadeout(id, speed)
{
 if(!speed) var speed = "normal";

 if(fadein_fadeout_opened == 0)
 {
  $('#pos_' + id).fadeIn(speed);
  fadein_fadeout_opened = id;
 }
 else if(fadein_fadeout_opened != 0)
 {
  if(id == fadein_fadeout_opened)
  {
   $('#pos_' + id).fadeOut(speed);
   fadein_fadeout_opened = 0;
  }
  else if (id != fadein_fadeout_opened)
  {
   $('#pos_' + fadein_fadeout_opened).fadeOut(speed);
   $('#pos_' + id).fadeIn(speed);
   fadein_fadeout_opened = id;
  }
 }
}



//*** SLIDE DOWN / SLIDE UP

var slidedown_slideup_opened = 0;
function slidedown_slideup(id, speed)
{
 if(!speed) var speed = "normal";

 if(slidedown_slideup_opened == 0)
 {
  $('#pos_' + id).slideDown(speed);
  slidedown_slideup_opened = id;
 }
 else if(slidedown_slideup_opened != 0)
 {
  if(id == slidedown_slideup_opened)
  {
   $('#pos_' + id).slideUp(speed);
   slidedown_slideup_opened = 0;
  }
  else if (id != fadein_fadeout_opened)
  {
   $('#pos_' + slidedown_slideup_opened).slideUp(speed);
   $('#pos_' + id).slideDown(speed);
   slidedown_slideup_opened = id;
  }
 }
}


//*** SHOW OR HIDE

function show_or_hide(id)
{
 if(id != null)
 {
  el = document.getElementById('pos_'+id);

  if(!el)
   return;
   el.style.display = el.style.display == 'block' ? 'none' : 'block';
 }
}



//*************************************************************************************
//************************* Wstawianie tekstu

function storeCaret(textEl)
{
 if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}


function wstaw(text, zm)
{
  var gdzie = document.getElementById(zm); 
 if (gdzie.createTextRange && gdzie.caretPos)
 {
	var caretPos = gdzie.caretPos;
	caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
	gdzie.focus();
 }
 else if (gdzie.selectionStart != undefined)
 {
	gdzie.value = gdzie.value.substring(0, gdzie.selectionStart) + text + gdzie.value.substring(gdzie.selectionStart);
	gdzie.focus();
 }
 else
 {
	gdzie.value += text;
	gdzie.focus();
 }
}



//************************************************************************
//************************* OBSŁUGA ZAKŁADEK

function selectContent(containerId, contentIndex, przycisk)
{
 // menu i zaznaczenie przycisku
 var pojemnik_menu = przycisk.parentNode;
 var elementy_menu = pojemnik_menu.getElementsByTagName("*");
 var ile_menu = elementy_menu.length;

 for ( var i = 0; i < ile_menu; i++ )
 {
  elementy_menu[i].className = 'off';
 }

 przycisk.className = 'on';

 // content
 var content = document.getElementById(containerId);
 var elementy_content = content.getElementsByTagName("div");
 var ile_content = elementy_content.length;

 for ( var i = 0; i < ile_content; i++ )
 {
  elementy_content[i].className = 'zakladka';
 }

 //pokazuje wybrany element
 elementy_content[contentIndex].className = 'selected';

		
 return false;
}



//************************************************************************
//************************* GENERATOR LOSOWEGO HASŁA

function randomPassword(length)
{
 chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
 pass = "";

 for(x=0; x < length; x++)
 {
  i = Math.floor(Math.random() * 62);
  pass += chars.charAt(i);
 }

 document.getElementById("pass1").value = pass;
 document.getElementById("pass2").value = pass;
}



//************************************************************************
//************************* SPRAWDZENIE ADRESU EMAIL

function clearField(fieldname)
{
 setStatus(fieldname, 'clear');

 if (fieldname == "name")
 {
  var button = document.getElementById('checkname');
  button.value = "Check Availability";
  button.disabled = '';
  button.style.display = '';
 }
}


function checkEmail(name) {
	var input = document.getElementById(name);
	if (name != "email1") {
		var first = document.getElementById("email1");
		if (first.value == input.value && input.value != null && input.value.length > 4 && input.value.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/))
			setStatus(name, 'good');
		else if (input.value.length <= 4)
			clearField(name);
		else setStatus(name, 'bad');
	} else {
		if (input.value != null && input.value.length > 4 && input.value.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/))
			setStatus(name, 'good');
		else if (input.value.length <= 4)
			clearField(name);
		else setStatus(name, 'bad');
	}
}


function checkPass(name) {
	var input = document.getElementById(name);
	if (name != "pass1") {
		var first = document.getElementById("pass1");
		if (first.value == input.value && input.value != null && input.value.length > 5)
			setStatus(name, 'good');
		else if (input.value.length < 1)
			clearField(name);
		else setStatus(name, 'bad');
	} else {
		if (input.value != null && input.value.length > 5)
			setStatus(name, 'good');
		else if (input.value.length < 1)
			clearField(name);
		else setStatus(name, 'bad');
	}
}


function setStatus(inputid, status) {
	var indicator = document.getElementById(inputid+'_status');
	if (indicator) {
		if (status == "good") {
			indicator.style.backgroundImage = "url('/gfx/layout/correct.gif')";
			}
	else if (status == "bad") {
	   indicator.style.backgroundImage = "url('/gfx/layout/incorrect.gif')";
	   }
	else {
	   indicator.style.backgroundImage = 'none';
	   }
	}
}

