//############################## [CMS PORTAL] - JAVA SCRIPTS
//### ver. 1.48 [2009-06-23]
//###
//### 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;
}


//************************* Pokazywanie / ukrywanie

otwarty = 0;
function show_hide(id)
{
 if(id != null)
 {
  if (otwarty > 0)
  {
   poprzedni = document.getElementById('pos_'+otwarty);
   poprzedni.style.display = 'none';
  }

  el = document.getElementById('pos_'+id);

  if(!el)
   return;
   el.style.display = 'block';
   otwarty = id;
 }
}


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;
}



//************************************************************************
//************************* WALIDACJA FORMULARZY

function error(tekst)
{
 if (errfound) return;
	window.alert(tekst);
errfound = true;
}


//************************* FORMULARZ KONTAKTOWY

function validate_contact(lang)
{
 errfound = false;
 var bledy = "";


 if (lang == "pl")
 {
  sender_name_txt = "Podaj swoje Imię";
  sender_email_txt = "Podaj swój adres e-mail";
  sender_email_err_txt = "Twój adres e-mail wydaje się być nieprawidłowy";
  subject_txt = "Podaj temat";
  text_txt = "Wpisz treść wiadomości";
 }
 else if (lang == "en")
 {
  sender_name_txt = "Please type Your name";
  sender_email_txt = "Please type Your e-mail address";
  sender_email_err_txt = "Your e-mail address is not valid";
  subject_txt = "Please type subject";
  text_txt = "Please type text";
 }
 else
 {
  sender_name_txt = sender_email_txt = sender_email_err_txt = subject_txt = text_txt = "BRAK TŁUMACZENIA DLA JĘZYKA: " + lang;
 }



 with(document.contact)
 {
  if (sender_name.value == "")
  {
   bledy += "* " + sender_name_txt + "!\n";
   sender_name.style.backgroundColor = "#FFB9B9";
  }
  else sender_name.style.backgroundColor = "#FFFFFF";


  if (sender_email.value == "")
  {
   bledy += "* " + sender_email_txt + "!\n";
   sender_email.style.backgroundColor = "#FFB9B9";
  }
  else if (sender_email.value != "" && (sender_email.value.length < 4 || sender_email.value.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/) == null))
  {
   bledy += "* " + sender_email_err_txt + "!\n";
   sender_email.style.backgroundColor = "#FFB9B9";
  }
  else sender_email.style.backgroundColor = "#FFFFFF";

  
  if (subject.value == "")
  {
   bledy += "* " + subject_txt + "!\n";
   subject.style.backgroundColor = "#FFB9B9";
  }
  else subject.style.backgroundColor = "#FFFFFF";


  if (text.value == "")
  {
   bledy += "* " + text_txt + "!\n";
   text.style.backgroundColor = "#FFB9B9";
  }
  else text.style.backgroundColor = "#FFFFFF";


  if (bledy != "") error(bledy);
 }
return !errfound;
}



//************************* DODAWANIE KOMENTARZA

function validate_com_logout(lang)
{
 errfound = false;
 var bledy = "";


 if (lang == "pl")
 {
  nick_txt = "Podaj nick";
  text_txt = "Wpisz treść komentarza";
 }
 else if (lang == "en")
 {
  nick_txt = "Please type Your nick";
  text_txt = "Please type comment";
 }
 else
 {
  nick_txt = text_txt = "BRAK TŁUMACZENIA DLA JĘZYKA: " + lang;
 }



 with(document.com_add)
 {
  if (nick.value == "")
  {
   bledy += "* " + nick_txt + "!\n";
   nick.style.backgroundColor = "#FFB9B9";
  }
  else nick.style.backgroundColor = "#FFFFFF";


  if (text.value == "")
  {
   bledy += "* " + text_txt + "!\n";
   text.style.backgroundColor = "#FFB9B9";
  }
  else text.style.backgroundColor = "#FFFFFF";


  if(bledy != "") error(bledy);
 }
return !errfound;
}



//************************* NEWSLETTER

function validate_newsletter(lang)
{
 errfound = false;
 var bledy = "";


 if (lang == "pl")
 {
  name_txt = "Podaj swoje Imię";
  email_txt = "Podaj swój adres e-mail";
  email_err_txt = "Twój adres e-mail wydaje się być nieprawidłowy";
 }
 else if (lang == "en")
 {
  name_txt = "Please type Your name";
  email_txt = "Please type Your e-mail address";
  email_err_txt = "Your e-mail address is not valid";
 }
 else
 {
  name_txt = email_txt = email_err_txt = "BRAK TŁUMACZENIA DLA JĘZYKA: " + lang;
 }



 with(document.newsletter)
 {
  if (name.value == "")
  {
   bledy += "* " + name_txt + "!\n";
   name.style.backgroundColor = "#FFB9B9";
  }
  else name.style.backgroundColor = "#FFFFFF";


  if (email.value == "")
  {
   bledy += "* " + email_txt + "!\n";
   email.style.backgroundColor = "#FFB9B9";
  }
  else if (email.value != "" && (email.value.length < 4 || email.value.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/) == null))
  {
   bledy += "* " + email_err_txt + "!\n";
   email.style.backgroundColor = "#FFB9B9";
  }
  else email.style.backgroundColor = "#FFFFFF";


  if (bledy != "") error(bledy);
 }
return !errfound;
}



//************************* RECOMMEND

function validate_recommend(lang)
{
 errfound = false;
 var bledy = "";

 if (lang == "pl")
 {
  recipient_email_txt = "Podaj adres e-mail Twojego znajomego";
  recipient_email_err_txt = "Adres e-mail Twojego znajomego wydaje się być nieprawidłowy";
  sender_email_txt = "Podaj swój adres e-mail";
  sender_email_err_txt = "Twój adres e-mail wydaje się być nieprawidłowy";
  sender_name_txt = "Podaj swoje Imię";
 }
 else if (lang == "en")
 {
  recipient_email_txt = "Please type the e-mail address of Your friend";
  recipient_email_err_txt = "E-mail address of your friend is not valid";
  sender_email_txt = "Please type Your e-mail address";
  sender_email_err_txt = "Your e-mail address is not valid";
  sender_name_txt = "Please type Your name";
 }
 else
 {
  recipient_email_txt = recipient_email_err_txt = sender_email_txt = sender_email_err_txt = sender_name_txt = "BRAK TŁUMACZENIA DLA JĘZYKA: " + lang;
 }


 with(document.recommend)
 {
  if (recipient_email.value == "")
  {
   bledy += "* " + recipient_email_txt + "!\n";
   recipient_email.style.backgroundColor = "#FFB9B9";
  }
  else if (recipient_email.value != "" && (recipient_email.value.length < 4 || recipient_email.value.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/) == null))
  {
   bledy += "* " + recipient_email_err_txt + "!\n";
   recipient_email.style.backgroundColor = "#FFB9B9";
  }
  else recipient_email.style.backgroundColor = "#FFFFFF";


  if (sender_email.value == "")
  {
   bledy += "* " + sender_email_txt + "!\n";
   sender_email.style.backgroundColor = "#FFB9B9";
  }
  else if (sender_email.value != "" && (sender_email.value.length < 4 || sender_email.value.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/) == null))
  {
   bledy += "* " + sender_email_err_txt + "!\n";
   sender_email.style.backgroundColor = "#FFB9B9";
  }
  else sender_email.style.backgroundColor = "#FFFFFF";


  if (sender_name.value == "")
  {
   bledy += "* " + sender_name_txt + "!\n";
   sender_name.style.backgroundColor = "#FFB9B9";
  }
  else sender_name.style.backgroundColor = "#FFFFFF";


  if (bledy != "") error(bledy);
 }
return !errfound;
}



//************************* PRESSROOM

function validate_pressroom_pl()
{
 errfound = false;
 var bledy = "";

 with(document.pressroom)
 {
  if (sender_name.value == "")
  {
   bledy += "* Podaj nazwę redakcji!\n";
   sender_name.style.backgroundColor = "#FFB9B9";
  }
  else sender_name.style.backgroundColor = "#FFFFFF";


  if (sender_email.value == "")
  {
   bledy += "* Podaj swój adres e-mail!\n";
   sender_email.style.backgroundColor = "#FFB9B9";
  }
  else if (sender_email.value != "" && (sender_email.value.length < 4 || sender_email.value.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/) == null))
  {
   bledy += "* Twój adres e-mail wydaje się być nieprawidłowy!\n";
   sender_email.style.backgroundColor = "#FFB9B9";
  }
  else sender_email.style.backgroundColor = "#FFFFFF";


  if (file_name.value == "")
  {
   bledy += "* Wybierz załącznik!\n";
   file_name.style.backgroundColor = "#FFB9B9";
  }
  else file_name.style.backgroundColor = "#FFFFFF";

  
  if (bledy != "") error(bledy);
 }
return !errfound;
}




//************************* SURVEYS

function validate_surveys(lang)
{
 errfound = false;
 var bledy = "";

 if (lang == "pl")
 {
  answer_txt = "Wpisz treść odpowiedzi";
  name_txt = "Podaj imię i nazwisko";
  email_txt = "Podaj swój adres e-mail";
  email_err_txt = "Twój adres e-mail wydaje się być nieprawidłowy";
  company_txt = "Podaj nazwę organizacji";
  accept_policy_txt = "Zaakceptuj politykę prywatności";
 }
 else
 {
  answer_txt = name_txt = email_txt = email_err_txt = company_txt = accept_policy_txt = "BRAK TŁUMACZENIA DLA JĘZYKA: " + lang;
 }


 with(document.surveys)
 {
  if (answer.value == "")
  {
   bledy += "* " + answer_txt + "!\n";
   answer.style.backgroundColor = "#FFB9B9";
  }
  else answer.style.backgroundColor = "#FFFFFF";


  if (name.value == "")
  {
   bledy += "* " + name_txt + "!\n";
   name.style.backgroundColor = "#FFB9B9";
  }
  else name.style.backgroundColor = "#FFFFFF";


  if (email.value == "")
  {
   bledy += "* " + email_txt + "!\n";
   email.style.backgroundColor = "#FFB9B9";
  }
  else if (email.value != "" && (email.value.length < 4 || email.value.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/) == null))
  {
   bledy += "* " + email_err_txt + "!\n";
   email.style.backgroundColor = "#FFB9B9";
  }
  else email.style.backgroundColor = "#FFFFFF";


  if (company.value == "")
  {
   bledy += "* " + company_txt + "!\n";
   company.style.backgroundColor = "#FFB9B9";
  }
  else company.style.backgroundColor = "#FFFFFF";


  if (accept_policy.checked == false)
  {
   bledy += "* " + accept_policy_txt + "!\n";
  }


  if (bledy != "") error(bledy);
 }
return !errfound;
}


//************************************************************************
//************************* 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;
}



//************************************************************************
//************************* WALIDACJA 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';
	   }
	}
}

