var active = 0;

var loadItem;

var loadTarget;

iLoad = function() {

// spin();

setTimeout("LoadData(loadTarget, loadItem);",500);

}

goBack = function() {

if (loadItem  && loadTarget ) iLoad();

else history.back();

}

rowHover = function(row, over) {

row.className = (over) ? 'DataHover' : 'DataEven';

}

function setOpacity (obj, val) {

	obj.style.opacity = val;

	div.style.KhtmlOpacity = val;

	div.style.filter = 'alpha(opacity = '+val*100+')';

}

var div;

var val;

var stop = 0;

var i = 0;

var step = 20;

var ID;

var appearOn = Array();

var disappearOn = Array();

function appear(id) {

  if (!id) return false;

  formLay = $(id)	

  Effect.Appear(formLay);

 }

function disappear(id) {

  if (!id) return false;

  formLay = $(id);

//   Effect.DropOut(formLay);

  Effect.Fade(formLay);

}

switchActive = function(event) {}

function Switch(o, dir) {}

function smoothSwitch(o) {}

function spin() {}

function ShowLogin() {}

function showInfo(mid,uid,box) {

  frame = $('inframe');

  frame.innerHTML = "Wait...";

  oper = (box.checked) ? 'set' : 'unset';

  LoadData('inframe','modules/set_module.php?mid='+mid+'&oper='+oper+'&uid='+uid, true);

  }

userAlert = function(alertMsg, autoHide) {

  var eLayer = $('systemAlert');

  var _alertMsg = $('alertMsg');

  var _autoHide = autoHide;

    if (window.attachEvent && !window.opera)

            eLayer.top = curPos+'px';

    else    eLayer.style.top = curPos;

  if (alertMsg) {

          _alertMsg.innerHTML = alertMsg;

          eLayer.appear();

          }

  if (_autoHide) setInterval("Effect.Fade('systemAlert');", 1000);

}



saveForm = function(id, allFields) {

var myForm = $(id);

var alertMsg = '';

	if (allFields) {

		var inputs = myForm.getInputs('text');

		for (i in inputs) {

// 			alert(/*inputs[i].id*/);

			if (inputs[i].value == '') {

			try { $(inputs[i].id).style.border = '2px solid red';}

			catch (e) {inputs[i].id = i+'_id';$(inputs[i].id).style.border = '2px solid red';}//Element.setStyle(inputs[i].id ,'border: 1px solid red');

// 			alert(inputs[i].name);

			if (!alertMsg) alertMsg = 'Uzupełnij proszę wszystkie pola.'

			}

		}

	if (alertMsg) { userAlert(alertMsg);alertMsg = '';return false;}

	}

	myForm.request( {

		onComplete: function(transport) {

			$('productData').innerHTML = transport.responseText;

                        Effect.Fade('spinner');

			userAlert('Dane zostały zapisane.', 1);

			}

		});

}

saveProductForm = function (id) {

  var myForm = $(id);

  var alertMsg = '';

  var params = myForm.serialize();

  new Ajax.Updater(

    'productData',

    myForm.action,

    {asynchronous:true,

      parameters:params, 

      onComplete: function(transport) {Effect.Fade('spinner');userAlert('Dane zostały zapisane.', 1);} 

    });

  iLoad();

  }

saveMyForm = function (id, targetID) {

var tID = $(targetID);

if (!tID) targetID = 'main';

var myForm = $(id);

	myForm.request( {

		onComplete: function(transport) {

			if (targetID) $(targetID).innerHTML = transport.responseText;

			}

		});

}

LoadSort = function (_Link ,Direction) {

var Dir = (Direction) ? Direction+'=true' : '';

LoadData('productData',_Link+'&'+Dir);

}

function goEdit(mode, id) {

location.href='/cms/?mode='+mode+'&exec=Edit&item='+id;

}

function loadEdit(mode, id) {

LoadData('productData','?mode='+mode+'&exec=Edit&item='+id);

}

function goDel(mode, id) {

if (confirm('Pozyja zostanie usunięta. '))

//LoadData('inframe','?mode='+mode+'&exec=Delete&item='+id);

location.href='cms/?mode='+mode+'&exec=Delete&item='+id;

}

function loadDel(mode, id) {

if (confirm('Pozyja zostanie usunięta. '))

LoadData('productData','?mode='+mode+'&exec=Delete&item='+id);

}

function goPermDel(mode, id) {

if (confirm('Pozyja zostanie usunięta.  '))

//LoadData('inframe','?mode='+mode+'&exec=Delete&item='+id);

location.href='/cms/?mode='+mode+'&exec=PernamentDelete&item='+id;

}

function productDel(mode, id)

{

if (confirm('Pozyja zostanie usunięta.  ')) {

// 	spin();

// 	LoadData('productData','?mode='+mode+'&exec=PernamentDelete&item='+id);

	LoadData('productData','?mode='+mode+'&exec=Delete&item='+id);

}

//location.href='cms/?mode='+mode+'&exec=PernamentDelete&item='+id;

}

function goOrder(mode, id)

{

location.href='cms/?mode='+mode+'&exec=Order&item='+id;

}

function goCat(BrandID, TypeID, ParentID)

{

ParentID = (ParentID) ? 'kategoria'+ParentID : '';

TypeID = (TypeID) ? TypeID : '';

BrandID = (BrandID) ? '?BrandID='+BrandID : '';

location.href = '/'+ParentID+TypeID+'.html'+BrandID;

}

function goProduct(id, BrandID, TypeID)

{

if (TypeID) TypeID = '&TypeID='+TypeID; else TypeID = '';

if (BrandID) BrandID = '&BranID='+BrandID; else BrandID = '';

//LoadData('mainData','?mode=shop&amp;data=Product&amp;item='+id+'&amp;BrandID='+BrandID+'&amp;TypeID='+TypeID);

location.href = 'cms/?mode=shop&data=Product&item='+id+BrandID+TypeID;

}

goBrand = function(BrandID) {

if (!BrandID) BrandID = 0; 

location.href = 'cms/?data=Product&ProducerID='+BrandID;

}

function goStatus(mode) {

  sel = $('status');

//	location.href='cms/?mode='+mode+'&StatusID='+sel.selectedIndex;

  LoadData('mainData','?mode='+mode+'&StatusID='+sel.selectedIndex);

  }

function Go(_link) {

  if (_link) location.href= _link;

  }

LoadData = function (o, _url, mod) {

   var url;

   url = (mod) ? 'cms/'+_url : 'cms/exec.php'+_url;

   new Ajax.Updater(o, url, {evalScripts:true} );

  }

getProvider = function () {

var Provider = '';

var OrderID = '';

var priceTo = '';

var productName = '';

Provider = '&Provider='+$('Provider').options[$('Provider').selectedIndex].value;

OrderID = ($('OrderID').value != '') ? '&OrderID='+$('OrderID').value : '' ;

Total = ($('Total').value != '') ? '&Total='+$('Total').value : '' ;



loadItem = '?mode=shop&data=Payment'+Provider+OrderID+Total;

LoadData('productData', '?mode=shop&data=Payment'+Provider+OrderID+Total);

}



function checkemail(str) {

  var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i ;

  if (filter.test(str))

    return true;

  else return false;

  }

checkRegForm = function ()

{

var stop = false;

var email = $('email');

var fname = $('first_name');

var cname = $('name');

var address1 = $('address1');

// var address2 = $('address2');

// var address3 = $('address3');

var postal_code = $('postal_code');

var city = $('Regcity');

var companyName = $('companyName');

var phone = $('phone');

var pass1 = $('Cpassword');

var pass2 = $('Cpassword2');

var regionID = $('regionID');

var passMissed = "Hasła są za krótkie lub różnią się.";

res = '';

if (pass1.value != pass2.value || pass1.value.length < 5) {

	res += '* '+passMissed+'<br>';

// 	alert(pass1.value+" * "+pass2.value);

	}

if (!checkemail(email.value)) res += "* Adres E-Mail jest nieprawidłowy<br>";

if (fname.value == '') res += "* Nie podano imienia<br>";

if (cname.value == '') res += "* Nie podano Nazwiska<br>";

if (address1.value == '') res += "* Nie podano ulicy<br>";

if (city.value == '') res += "* Nie podano miasta<br>";

if (phone.value == '') res += "* Nie podano nr. telefonu<br>";

if (regionID.selectedIndex < 1) res += "* Nie wybrano województwa<br><br>";



if (res) {

	res = "<b>Proszę uzupełnić wszystkie wymagane pola.</b> <br><br><blockquote style='text-align:left;'>"+res+"</blockquote>";

	userAlert(res);

	return false;

	}

	else

// 	return true;

	$('registerForm').submit();

}



checkOfficeRegForm = function ()

{

var stop = false;

var email = $('email');

var fname = $('first_name');

var cname = $('name');

var companyName = $('companyName');

var add_info = $('add_info');

var add_info_kom = $('add_info_kom');

var pass1 = $('Cpassword');

var pass2 = $('Cpassword2');

var agr = $('agreement');

var passMissed = "Hasła są za krótkie lub różnią się.";

res = '';

if ( pass1 && pass2 && (pass1.value != pass2.value || pass1.value.length < 5)) {

	res += '* '+passMissed+"\n";

// 	alert(pass1.value+" * "+pass2.value);

	}

if (email && !checkemail(email.value)) res += "* Adres E-Mail jest nieprawidłowy\n";

if (fname && fname.value == '') res += "* Nie podano imienia\n";

if (cname && cname.value == '') res += "* Nie podano Nazwiska\n";

if (companyName && companyName.value == '') res += "* Nie podano nazwy firmy lub redakcji\n";

if (add_info && add_info.value == '') res += "* Nie podano nr. telefonu\n";

if (add_info_kom && add_info_kom.value == '') res += "* Nie podano nr. telefonu komórkowego\n";

if (agr && !agr.checked) res += "* Proszę zaakceptować zgode na przetwarzanie danych\n";



if (res) {

/*	res = "<b>Proszę uzupełnić wszystkie wymagane pola.</b> <br><br><blockquote style='text-align:left;'>"+res+"</blockquote>";

	userAlert(res);*/

	res = "Proszę uzupełnić wszystkie wymagane pola.\n"+res+"";

	alert(res);

	return false;

	}

	else

// 	return true;

	$('registerForm').submit();

	

	return false;

}



checkNotifyForm = function () {

  var stop = false;

  var email = $('Nemail');

  var Nname = $('Nname');

  var Nmessage = $('Nmessage');

  

  res = '';

  if (!checkemail(email.value)) res += "* Adres E-Mail jest nieprawidłowy<br><br>";

  if (Nname.value == '') res += "* Podaj imię osoby polecającej<br><br>";

  if (Nmessage.value == '') res += "* Proszę wpisać wiadomość<br><br>";

  

  if (res) {

    res = "<b>Proszę uzupełnić wszystkie wymagane pola.</b> <br><br><blockquote style='text-align:left;'>"+res+"</blockquote>";

    userAlert(res);

    return false;

    } else return true;

// 	document.registerForm.submit();

  }



checkQuestionForm = function () {

  var stop = false;

  var email = $('Nemail');

  var Nname = $('Nname');

  var Nmessage = $('Nmessage');

  var Ncat = $('Ncat');

  

  res = '';

  if (!checkemail(email.value)) res += "* Proszę podać poprawny adres email<br><br>";

  if (Nname.value == '') res += "* Podaj swoje Imię<br><br>";

  if (Nmessage.value == '') res += "* Proszę wpisać pytanie<br><br>";

  if (Ncat.selectedIndex == 0) res += "* Proszę wybrać Kategorię<br><br>";

  

  if (res) {

      res = "<b>Proszę uzupełnić wszystkie wymagane pola.</b> <br><br><blockquote style='text-align:left;'>"+res+"</blockquote>";

      userAlert(res);

      return false;

      } else return true;

  // 	document.registerForm.submit();

  }

checkQuestionKonkursForm = function () {
	
	var stop = false;
	
	var email = $('Nemail');
	
	var Nname = $('Nname');
	
	var NPhone = $('NPhone');
	var NAdress = $('NAdress');
	var Nmessage = $('Nmessage');
	var Nagreement = $('Nagreement');
	
	var Ncat = $('Ncat');
	
	
	
	res = '';
	
	if (!checkemail(email.value)) res += "* Proszę podać poprawny adres email<br><br>";
	
	if (Nname.value == '') res += "* Podaj swoje Imię<br><br>";
	
	if (NPhone.value == '') res += "* Proszę wpisać telefon kontaktowy<br><br>";
	
	if (NAdress.value == '') res += "* Proszę wpisać adres<br><br>";
	
	if (!Nagreement.checked) res += "* Wyraź zgodę na przetwarzanie danych<br><br>";
	if (Nmessage.value == '') res += "* Proszę wpisać pytanie<br><br>";
	
	if (Ncat.selectedIndex == 0) res += "* Proszę wybrać Kategorię<br><br>";
	
	
	
	if (res) {
		
		res = "<b>Proszę uzupełnić wszystkie wymagane pola.</b> <br><br><blockquote style='text-align:left;'>"+res+"</blockquote>";
		
		userAlert(res);
		
		return false;
		
	} else return true;
	
	// 	document.registerForm.submit();
	
}



checkContactForm = function () {

  var stop = false;

  var email = $('Nemail');

  var Nname = $('Nname');

  var Nphone = $('Nphone');

  var Nmessage = $('Nmessage');

  

  res = '';

  if (!checkemail(email.value)) res += "* Adres E-Mail jest nieprawidłowy<br><br>";

  if (Nname.value == '') res += "* Podaj imię i nazwisko<br><br>";

  if (Nmessage.value == '') res += "* Proszę wpisać wiadomość<br><br>";

  if (Nphone.value == '') res += "* Proszę wpisać numer telefonu<br><br>";



  if (res) {

    res = "<b>Proszę uzupełnić wszystkie wymagane pola.</b> <br><br><blockquote style='text-align:left;'>"+res+"</blockquote>";

    userAlert(res);

    return false;

    } else return true;

// 	document.registerForm.submit();

  }



checkNewsletter = function () {

  res = '';

  var email = $('newsletter_email');

  if (!checkemail(email.value)) res += "Prosze wpisać poprawny adres E-mail<br><br>";

    if (res) {

            userAlert(res);

            return false;

            }

            else

            return true;

  }

  

itemToggle = function (id) {

  if ($(id).style.display == 'none')

      Effect.BlindDown(id);

  else Effect.BlindUp(id);

  return false;

}
