var rowHighlight = 1;
/*********************************************************/
/* Highlighting current row                              */
/*********************************************************/

var catArray = new Array;
var selType = '';
var selId = '';
var selPos = '';
var selPCat = '';

function o(identyfikator) {
	return document.getElementById(identyfikator);
}

function positionAll(prefix,mod){
	for(inc=0;inc<catArray.length;inc++){
		//alert(catArray[0]);
		var pcat = catArray[inc];
		var curPos=1;
		//alert(prefix+'_'+pcat+'_'+curPos);
		while(o(prefix+'_'+pcat+'_'+curPos)!=null){
			chooseLayer = o(prefix+'_'+pcat+'_'+curPos);
			chooseLayer.style.display = mod;
			curPos++;
		};
	}
}

function positionChoose(pcat,pos,id,type){
	
	var ident = pcat+'_'+pos;
	var curPos = 1;
	selPCat = pcat;
	selPos = pos;
	selType = type;
	selId = id;
		
	positionMark(pcat,pos,1);
	positionAll('pc','none');
	
	while(o('pc_'+pcat+'_'+curPos)!==null){
		setLayer = o('ps_'+pcat+'_'+curPos);
		curPos++;
		
		if(curPos!=(pos+1) && curPos!=(pos+2))		
			setLayer.style.display = "";		
	}	
	
	if(o('ps_'+pcat+'_'+curPos)!==null && curPos!=(pos) && curPos!=(pos+1))	{
		setLayer = o('ps_'+pcat+'_'+curPos);
		setLayer.style.display = "";
	}
	
	if(o('pr_'+pcat+'_'+pos)!==null)	{
		returnLayer = o('pr_'+pcat+'_'+pos);
		returnLayer.style.display = "";
	}
}

function positionReturn(pcat,pos){
	
	positionAll('pc','');
	positionAll('ps','none');
	positionMark(pcat,pos,0);
	
	if(o('pr_'+pcat+'_'+pos)!==null)	{
		undoLayer = o('pr_'+pcat+'_'+pos);
		undoLayer.style.display = "none";
	}
}

function positionSet(pcat,pos,dest){
	
	positionAll('ps','none');
	dest += '&'+selType+"="+selId+"&pos="+pos;
	//alert(dest);
	window.location.href=dest;
}

function positionHigh(pcat,pos,mod){
		
	if(o('pline_'+pcat+'_'+pos)!==null)	{
		lineLayer = o('pline_'+pcat+'_'+pos);
		lineLayer.style.backgroundColor = mod;
	}
}

function positionMark(pcat,pos,hiLo){
	
	if(hiLo){
		if(o('prow_'+pcat+'_'+pos)!==null) highRow(o('prow_'+pcat+'_'+pos),0);		
		rowHighlight = 0;
		newColor = '#ffc581';
	}
	else{
		rowHighlight = 1;
		newColor = '';
	}
	
	if(o('prow_'+pcat+'_'+pos)!==null)	{
		rowLayer = o('prow_'+pcat+'_'+pos);
		rowLayer.style.backgroundColor = newColor;
	}
}

/*********************************************************/
/* Enable accesskeys in IE                               */
/*********************************************************/

var accessKeyEnabled = true;

function useAccessKey (evt) {
	if (accessKeyEnabled == true) {
		if (event.altKey) {
			event.srcElement.click();
		}
	} else {
		event.srcElement.blur();
		accessKeyEnabled = true;
	}
}

function releaseAccessKey() {
	if (accessKeyEnabled == false) {
		accessKeyEnabled = true;
	}
}

function initAccessKey() {
	if (navigator.appName == "Microsoft Internet Explorer") {
		for (i=0;i<document.all.length;i++) {
			a = document.all(i);
			if (a.tagName == 'A' && a.accessKey != '') {
				a.blur();
				a.onfocus = useAccessKey;
			}
		}
		if (event.altKey) {
			accessKeyEnabled = false;
			document.onkeyup = releaseAccessKey;
			setTimeout ('releaseAccessKey()', 100);
		}
	}
} 


/*********************************************************/
/* Highlighting current row                              */
/*********************************************************/

function highRow ( theRow, hiLo ){
	
		var newColor = null;

		if (!rowHighlight)	return true;
		if (hiLo == 1) newColor = '#E4E5FF';
		else newColor = '' ;

		// 2. Gets the current row and exits if the browser can't get it
		if (typeof(document.getElementsByTagName) != 'undefined') {
			var theCells = theRow.getElementsByTagName('td');
		}
		else if (typeof(theRow.cells) != 'undefined') {
			var theCells = theRow.cells;
		}
		else {
			return false;
		}
        var c = null;

        for (c = 0; c < theCells.length; c++) {
           theCells[c].style.backgroundColor = newColor;
         }
		
 	return true;
}


/*********************************************************/
/* Confirms deleting the object                          */
/*********************************************************/

function confirmLink( theLink, confirmMsg )
{
    var is_confirmed = confirm(confirmMsg);
    if (is_confirmed) {
        theLink.href += '&is_js_confirmed=1';
    }

    
} // end of the 'confirmLink()' function


function confirmLink2( theLink, confirmMsg )
{
    var is_confirmed = confirm(confirmMsg);
    if (is_confirmed) {
        theLink += '&is_js_confirmed=1';
		window.location.href=theLink; 
    }

    
} // end of the 'confirmLink()' function


/*********************************************************/
/* Checking an email                                     */
/*********************************************************/
function checkEmail() {
			
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.cf._actualplaceholder_zawartosc_strony_From.value)) {
			;
		} else {
	    	alert('Nie poprawny adres e-mail nadawcy!\nProszę wprowadzić ponownie.');
			return;
		}
		
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.cf._actualplaceholder_zawartosc_strony_To.value)) {
			;
		} else {
	    	alert('Nie poprawny adres e-mail odbiorcy!\nProszę wprowadzić ponownie.');
			return;
		}
		
	if (document.cf._actualplaceholder_zawartosc_strony_Agree.checked == 0) {
		alert('Porszę o wyrażenie zgody na przetwarzanie informacji.');
		return;
	}
		
		document.cf.submit();
	}


function openPage( theUrl,W,H, scrollbar ){
    var theWin ="'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars="+scrollbar+",resizable=0,width="+W+",height="+H+"'"
	littleWin = window.open(theUrl,'opened',theWin);
	//littleWin.resizeTo(W+10,H+29);
 	littleWin.focus();

}

function validateAnkieta(form){
	var zatwierdz = true
	
	if(form.pytanie.value==""){
		zatwierdz = false;
	}
	if (zatwierdz){
		form.submit();
	}
	else{
		alert('Uzupelnij formularz');
	}
}

function validateOdpowiedz(form){
	var zatwierdz = true
	
	if(form.odpowiedz.value==""){
		zatwierdz = false;
	}
	
	if (zatwierdz){
		form.submit();
	}
	else{
		alert('Uzupelnij formularz!');
	}
}

function validateBanners(form , type ){
	var zatwierdz = true
	
	if(form.nazwa.value==""){
		zatwierdz = false;
	}
	if( form.plik.value=="" && type=="add" ){
		zatwierdz = false;
	}	
	if (zatwierdz){
		form.submit();
	}
	else{
		alert('Uzupelnij formularz!');
	}
}

function validateBannersKat( form ){
	var zatwierdz = true
	
	if(form.nazwa.value==""){
		zatwierdz = false;
	}
	if(form.frequency.value=="" && !isNumberString(form.frequency.value)){
		zatwierdz = false;
	}
	if(form.elements.value=="" && !isNumberString(form.elements.value) ){
		zatwierdz = false;
	}
	
	if (zatwierdz){
		form.submit();
	}
	else{
		alert('Uzupelnij formularz!');
	}
}
