function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+";path=/";
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function changelanguage(lang)
{
setCookie('language',lang,7);
setCookie('lock_lang',1,1);
document.location="";
}
function select_setselected(select,index)
{
var s=document.getElementsByName(select);
s[0].selectedIndex=index;
}
function change_region(region)
{
setCookie('region',region);
setCookie('lock_region',1);
document.location="";
}
function change_departament(dep)
{
setCookie('departament',dep);
setCookie('lock_departament',1);
document.location="";
}
function smartyselect(id,targetvalue)
{
if(targetvalue!=null)
{
var s=$(id);
x=0;
while(s.value!=targetvalue & x<=s.length)
{
s.selectedIndex=s.selectedIndex+1;
x++;
};
};
}
//////////////////////////////////////////////
function load_subcats()
{
dojo.byId('subcat_tr').style.display='';
dojo.byId('loadingIMG').style.display='';
dojo.byId('response').style.display='none';
dojo.xhrPost( { // ?
        // The following URL must match that used to test the server.
content:{'val':dijit.byId("cat").getValue()},
url:"public/ajax_community/addoffer_subcats.php", 
        handleAs: "json",

        load: function(response, ioArgs) { // ?
if(response.items[0].name!='none')
{
dojo.byId('response').style.display='';
//dojo.byId('response').innerHTML = response;
dojo.byId('loadingIMG').style.display='none';
 standardData = new dojo.data.ItemFileReadStore({data:response});
 
    var stdDataSelect = dijit.byId('subcat');
	stdDataSelect.store = standardData;
	 stdDataSelect.setDisplayedValue('');
	if(window.subcatcallbask!=null)
 {
 stdDataSelect.setValue(window.subcatcallbask);
 };
    
dojo.parser.parse(dojo.byId("subcat_r_td"));
}
else
{
dojo.byId('subcat_tr').style.display='none';
};
          return response; 
        },

        // The ERROR function will be called in an error case.
        error: function(response, ioArgs) { // ?
          console.error("HTTP status code: ", ioArgs.xhr.status); // ?
          return response; // ?
          }
        });
}
function enable_depart()
{
if($('region').value==12)
{
$('departamenty').disabled=false;
}
else
{
$('departamenty').disabled=true;
};
}
function enable_premium()
{
if(dijit.byId('premium').getValue()==1)
{
dijit.byId('okres_premium').setDisabled(false);
}
else
{
if(!dijit.byId('okres_premium').isDisabled)
{
dijit.byId('okres_premium').setDisabled(true);
};
};
}
function picture_upload_init()
{
var WindowObjectReference;
var strWindowFeatures = "menubar=no,location=no,resizable=no,scrollbars=no,status=no,width=450,height=500";
WindowObjectReference = window.open("uploadinterface,1",
"CNN_WindowName", strWindowFeatures);
WindowObjectReference.focus();
}
function refresh_pictures_1(name)
{
window.focus();
var x;
x=$('picref');
x.innerHTML='<img src="images/AjaxLoadingIcon.gif"/>';
 var req = mint.Request();
	req.method='POST';
	req.AddParam("val", name);
	req.evalScripts =true;
    req.Send("public/ajax_community/ajaxpicturelister.php", "");
	req.OnSuccess=function () {if(this.responseText!='none'){
	x.innerHTML=this.responseText;
	}
	
	};
}
function subcats(val,tar) {
$('loadingIMG').style.display='';
    var req = mint.Request();
	req.method='POST';
	req.AddParam("val", val);
	req.AddParam("tar", tar);
	req.evalScripts =true;
    req.Send("public/ajax_community/addoffer_subcats.php", "");
	req.OnSuccess=function () {if(this.responseText!='none'){
	$('loadingIMG').style.display='none';
	$('subcat_tr').style.display='';
	$('response').style.display='';
	$('response').innerHTML=this.responseText;
	}
	else{$('subcat_tr').style.display='none';};
	};
} 
function licz(f)
{
var x=document.getElementById('koszt');
x.innerHTML=f;
}
function kontrolagazetki(obj,l)
{
var f=0;
var g=document.getElementById("gazetka");
if(g.checked)
{
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
{
f=3;
obj.value=obj.value.substring(0,mlength)
alert(l);
}
else if(obj.getAttribute && obj.value.length<=mlength && obj.value.length<=300)
{
f=1;
}
else if(obj.getAttribute && obj.value.length<=mlength && obj.value.length<=400)
{
f=2;
}
else if(obj.getAttribute && obj.value.length<=mlength && obj.value.length<=500)
{
f=3;
}
};
licz(f);
}