function GetKatAj(kat){

readfilepost(kat,'','inc/fileajax/subcat.php','divkataj');
}

function RetKatAj(){

readfilepost('','','inc/fileajax/cat.php','divkataj');
}

function readfile(val,val1,file,target){
advAJAX.get({
  url: file,
	parameters : {
    "par" : val,
    "par1" : val1
  },
  onSuccess : function(obj) { 
  	document.getElementById(target).innerHTML = obj.responseText;
  },
onLoading : function(obj) {
document.getElementById(target).innerHTML= '<img src="img/loading.gif"/>';
},
  onError : function(obj) { 
    alert("Error: " + obj.status); 
  }
});
}


function readfilepost(val,val1,file,target){
advAJAX.post({
  url: file,
	parameters : {
    "par" : val,
    "par1" : val1
  },
  onSuccess : function(obj) { 
  	document.getElementById(target).innerHTML = obj.responseText;
  },
onLoading : function(obj) {
document.getElementById(target).innerHTML= "<img src=\"img/loading.gif\"/>";
},
  onError : function(obj) { 
    alert("Error: " + obj.status); 
  }
});
}


function postsenddata(forma,file,target){
advAJAX.submit(document.getElementById(forma), 
  {
  	url: file,
    onSuccess : function(obj) { 
      document.getElementById(target).innerHTML = obj.responseText;
    },
    

onLoading : function(obj) {
document.getElementById(target).innerHTML= "<img src=\"img/loading.gif\"/>";
},
    onError : function(obj) { 
      alert("Error: " + obj.status);
    }
  }
);	
}





function placepop() {
	bh=document.body.clientHeight;
	bw=document.body.clientWidth;
	pw=document.getElementById('popup').clientWidth;
	ph=document.getElementById('popup').clientHeight;
	document.getElementById('popup').style.left=((bw-pw)/2)+'px';
	document.getElementById('popup').style.top='200px';
}



function placepophide(){
	
document.getElementById('popup').style.display='none';	

}




function validezgloszenie(){

if(document.formzgloszenie.rodzaj.value == 1){
	
if(form1()){return true;}else{return false;}	

}else if(document.formzgloszenie.rodzaj.value == 2){
	
if(form1() && form2()){return true;}else{return false;}


}else if(document.formzgloszenie.rodzaj.value == 3){
	
	if(form2()){return true;}else{return false;}
}	
}




function form1(){

if(document.formzgloszenie.nazwamail.value==""){
alert("Proszę wpisać imie i nazwisko lub nazwe firmy");
error_nul('nazwamail');
return false;
	}
	ok_elemnt('nazwamail');
	
if(document.formzgloszenie.telmail.value=="" && document.formzgloszenie.email_mail.value==""){
alert("Proszę wpisać numer telefonu lub adres e-mail niezbędny do kontaktu");
error_nul('telmail');
error_nul('email_mail');
return false;
	}
	ok_elemnt('telmail');ok_elemnt('email_mail');
	
	
	
if(document.formzgloszenie.email_mail.value!=""){
	
	if(!email_validate(document.formzgloszenie.email_mail.value)){
alert("Adres e-mail jest nieprawidłowy");		
error_nul('email_mail');
return false;		
	}

}
ok_elemnt('email_mail');			

return true;
}


function form2(){

if(document.formzgloszenie.nazwa.value==""){
alert("Proszę wpisać nazwe jaka będzie widniała na stronie");
error_nul('nazwa');
return false;
	}ok_elemnt('nazwa');
	
	
if(document.formzgloszenie.kategoria[0].value==""){
alert("Proszę wybrać kategorie");
return false;
	}

	
	
if(document.formzgloszenie.wojewodztwoz.value==""){
alert("Proszę wybrać województwo");
error_nul('wojewodztwoz');

return false;
	}
	ok_elemnt('wojewodztwo');	
	

if(document.formzgloszenie.powiatwysz.value==""){
alert("Proszę wybrać powiat");
error_nul('powiatwysz');

return false;
	}
	ok_elemnt('powiatwysz');
	

if(document.formzgloszenie.miasto.value==""){
alert("Proszę wpisać nazwe miejscowości");
error_nul('miasto');

return false;
	}
	ok_elemnt('miasto');	
	


if(document.formzgloszenie.ulica.value==""){
alert("Proszę wpisać nazwę ulicy");
error_nul('ulica');

return false;
	}
	ok_elemnt('ulica');		
	
	
if(document.formzgloszenie.numer.value==""){
alert("Proszę wpisać numer budynku");
error_nul('numer');

return false;
	}
	ok_elemnt('numer');				

return true;
}

function zgloszenie(val){

if(val == 1){

show_hiden_div("graficzny","S");
show_hiden_div("txtgraficzny","S");
show_hiden_div("txtpremium","H");
show_hiden_div("podstawowy","H");
show_hiden_div("formwpis","H");
show_hiden_div("premiumkat","H");


show_hiden_div("sub","S");	

}else if(val == 2){
	
show_hiden_div("podstawowy","H");
show_hiden_div("formwpis","S");
	
	
show_hiden_div("txtgraficzny","H");
show_hiden_div("premiumkat","S");
show_hiden_div("graficzny","S");
show_hiden_div("txtpremium","S");


show_hiden_div("sub","S");		
	
}else if(val == 3){
show_hiden_div("podstawowy","S");
show_hiden_div("formwpis","S");
show_hiden_div("graficzny","H");
show_hiden_div("txtpremium","H");
show_hiden_div("txtgraficzny","H");
show_hiden_div("premiumkat","H");
show_hiden_div("sub","S");		
}else{
	
show_hiden_div("podstawowy","H");
show_hiden_div("formwpis","H");
show_hiden_div("graficzny","H");
show_hiden_div("txtpremium","H");
show_hiden_div("sub","H");	
	
	
}	
	
	

}





function show_hiden_div(identyfikator,stan) { 
	
if(stan == "H"){
	
document.getElementById(identyfikator).style.display = "none";
	
}else{
	
document.getElementById(identyfikator).style.display = "inline";
	
}
}



function TrackCount(fieldObj,countFieldName,maxChars)
{
	var countField = eval("fieldObj.form."+countFieldName);
	var diff = maxChars - fieldObj.value.length;

	if (diff < 0)
	{
		fieldObj.value = fieldObj.value.substring(0,maxChars);
		diff = maxChars - fieldObj.value.length;
	}
	document.getElementById(countFieldName).innerHTML = diff;
}

function LimitText(fieldObj,maxChars)
{
	var result = true;
	if (fieldObj.value.length >= maxChars)
	result = false;

	if (window.event)
	window.event.returnValue = result;
	return result;
}

function liczby(x){
x.value=x.value.replace(/\D/g,'')
}







function email_validate(src) 
{
  var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
  return regex.test(src);
}

// menu
var menuOtw=false;
function close_menu(num)
{
	if (document.getElementById('menu_cat_'+num))
		document.getElementById('menu_cat_'+num).className='menu1_off';
}

function menu_cat_change(num) {
	if (menuOtw==num){
    close_menu(menuOtw);
    menuOtw=false;
  } else {  
    if (menuOtw!=false) close_menu(menuOtw);			
   
    if (document.getElementById('menu_cat_'+num))
      document.getElementById('menu_cat_'+num).className='menu1_on';      
	menuOtw=num;
  }
  return false;  
}

function MenuStart(dId) {
  menu_cat_change(dId);
}


function error_nul(element) {
	
document.getElementById(element).className = 'error_null';

        }

function ok_elemnt(element) {
	
document.getElementById(element).className = 'inputform';

        } 
 function liczby(x){
x.value=x.value.replace(/\D/g,'')
} 


function readfile(val,val1,file,target){
advAJAX.get({
  url: file,
	parameters : {
    "par" : val,
    "par1" : val1
  },
  onSuccess : function(obj) { 
  	document.getElementById(target).innerHTML = obj.responseText;
  },
onLoading : function(obj) {
document.getElementById(target).innerHTML= '<img src="img/loading.gif"/>';
},
  onError : function(obj) { 
    alert("Error: " + obj.status); 
  }
});
}



/***********************************************
* Cool DHTML tooltip script II- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetfromcursorX=12 //Customize x offset of tooltip
var offsetfromcursorY=10 //Customize y offset of tooltip

var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV
document.write('<img id="dhtmlpointer" src="img/arrow2.gif">') //write out pointer image

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thewidth, thecolor){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var nondefaultpos=false
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth){
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=curX-tipobj.offsetWidth+"px"
nondefaultpos=true
}
else if (curX<leftedge)
tipobj.style.left="5px"
else{
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
pointerobj.style.left=curX+offsetfromcursorX+"px"
}

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight){
tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
nondefaultpos=true
}
else{
tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
pointerobj.style.top=curY+offsetfromcursorY+"px"
}
tipobj.style.visibility="visible"
if (!nondefaultpos)
pointerobj.style.visibility="visible"
else
pointerobj.style.visibility="hidden"
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
pointerobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

document.onmousemove=positiontip      
