DOLAR= function(id) {
	if(!id) return null;
		
	var e = (typeof id == "string") ? document.getElementById(id) : id;
	
	if(!e) return null;
	
	return e;
}
function glosuj(myId,myIp){
  var req = mint.Request();
  req.method="POST";
  req.AddParam("id",myId);
  req.AddParam("ip",myIp);
  req.OnSuccess = function() {
     DOLAR("buttGlosuj"+myId).style.display="none";
     DOLAR("spanGlosuj"+myId).innerHTML=this.responseText;
  }
  req.Send("glosuj.php5");
}
function refreshCaptcha(){
  DOLAR("imgCaptcha").src="captcha.php5?sid="+new Date().getTime();
  DOLAR("captcha").value="";
}
function myTrim(tresc){
  return tresc.replace(new RegExp("[<br /> \n\r\t]+", "g"), "");
}
function myEmail(tresc){
  var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
  if(tresc.search(emailRegEx) == -1){
    return false;
  }else{
    return true;
  }
}
function dodatki(){
  var tabButt = document.getElementsByTagName("button");
  for(i=0;i<tabButt.length;i++){
    if(tabButt[i].className==""){
      tabButt[i].className="butMenu";
      tabButt[i].onmouseover = function(){this.className="butMenuHover"};
      tabButt[i].onmouseout = function(){this.className="butMenu"};
    }
  }
}
function rozmiarDiv(iObj){
    var obj={};
    obj.width=DOLAR(iObj).offsetWidth;
    obj.height=DOLAR(iObj).offsetHeight;
    return obj;
}
function confirmation() {
	var answer = confirm("Czy jesteś pewien?");
	if (answer){
		return true;
	}
	else{
		return false;
	}
}
function chkAjax(){
  var req = mint.Request();
  req.OnSuccess = function() {
     alert(this.responseText);
  }
  req.Send("testMySql.txt");
}
function ocen(ocena,id){
  var req = mint.Request();
  req.method="POST";
  req.AddParam("id",id);
  req.AddParam("ocena",ocena);
  req.OnSuccess = function() {
     DOLAR("tuSaButoony").style.display="none";
  }
  req.Send("ocena.php5","tuTrafiSrednia");
  //req.Send("ocena.php5");
}
function ustawMojSite(){
   if(DOLAR('czemuNie')){
     var tmpSize = rozmiarDiv(DOLAR("divMain"));
     var tmpSizeLeft = rozmiarDiv(DOLAR("divLeft"));
     //alert(tmpSizeLeft.height+" | "+tmpSize.height);
     if(tmpSizeLeft.height>tmpSize.height){
        DOLAR("divMain").style.height=tmpSizeLeft.height+"px";
        //alert("dostosuj main");
     }else{
        DOLAR("divLeft").style.height=tmpSize.height+"px";
        DOLAR("divRight").style.height=tmpSize.height+"px";
        //alert("dostosuj left & right");
     }
     //alert(tmpSize.height);
   }
}
onLoad = function() {
  //$('.myCssClass')   pobiera elementy o danej klasie css
  if(DOLAR("buttonZagraj")){
     $("#buttonZagraj").addClass("butonZagraj");
  }
   if(DOLAR("TuMojaGra")){
      //toogleSite(DOLAR("TuMojaGra").getAttribute("idSchemat"));
      //ustawMojSite();
      var so = new SWFObject(DOLAR("TuMojaGra").getAttribute("rel"), "game", DOLAR("TuMojaGra").style.width, DOLAR("TuMojaGra").style.height, "9", "#062224");
      so.addParam('salign', 'tl');
      so.addParam('align', 'middle');
      so.write("TuMojaGra");
   }else{
      //ustawMojSite();
   }
}

function toogleSite(czyToogle){
  /*
  //alert(czyToogle);
  var req = mint.Request();
  req.method="POST";
  req.AddParam("id",czyToogle);
  //req.evalResponse = true;
  //req.evalScripts = true;
  req.OnError = function() {
    alert("Error "+this.statusText);
  }
  req.OnSuccess = function() {
    //alert(this.responseText);
    DOLAR("divLeft").innerHTML="";
    DOLAR("divRight").innerHTML="";
    DOLAR("divLeft").innerHTML=this.responseText;
    DOLAR("divRight").innerHTML=this.responseText;
    EvalScripts(this.responseText,DOLAR("divLeft"));
    EvalScripts(this.responseText,DOLAR("divRight"));
  }
  req.Send("test/reklama.php");
  */
  switch(czyToogle){
    case "2" :
    DOLAR("divLeft").style.width="1000px";
    DOLAR("divLeft").style.margin="0px";
    DOLAR("divLeft").style.padding="0px";
    DOLAR("divRight").style.width="1000px";
    DOLAR("divRight").style.margin="0px";
    DOLAR("divRight").style.padding="0px"; 
    DOLAR("divCont").style.width="1000px";
    DOLAR("divCont").style.margin="0px";
    DOLAR("divCont").style.padding="0px";
    DOLAR("divMargCont").style.width="980px";
    DOLAR("divMargCont").style.margin="0px 10px 0px 10px";
    DOLAR("divMargCont").style.padding="0px";
    DOLAR("divMain").style.width="980px";
    DOLAR("divMain").style.margin="0px";
    DOLAR("divMain").style.padding="0px";
    break;
    case "1" :
    DOLAR("divLeft").style.width="160px";
    DOLAR("divLeft").style.margin="0px";
    DOLAR("divLeft").style.padding="0px";
    DOLAR("divRight").style.width="160px";
    DOLAR("divRight").style.margin="0px";
    DOLAR("divRight").style.padding="0px";
    DOLAR("divCont").style.width="680px";
    DOLAR("divCont").style.margin="0px";
    DOLAR("divCont").style.padding="0px";
    DOLAR("divMargCont").style.width="660px";
    DOLAR("divMargCont").style.margin="0px 10px 0px 10px";
    DOLAR("divMargCont").style.padding="0px";
    DOLAR("divMain").style.width="660px";
    DOLAR("divMain").style.margin="0px";
    DOLAR("divMain").style.padding="0px";
    break;
    default :
    DOLAR("divLeft").style.width="160px";
    DOLAR("divLeft").style.margin="0px";
    DOLAR("divLeft").style.padding="0px";
    DOLAR("divRight").style.width="160px";
    DOLAR("divRight").style.margin="0px";
    DOLAR("divRight").style.padding="0px";
    DOLAR("divCont").style.width="680px";
    DOLAR("divCont").style.margin="0px";
    DOLAR("divCont").style.padding="0px";
    DOLAR("divMargCont").style.width="660px";
    DOLAR("divMargCont").style.margin="0px 10px 0px 10px";
    DOLAR("divMargCont").style.padding="0px";
    DOLAR("divMain").style.width="660px";
    DOLAR("divMain").style.margin="0px";
    DOLAR("divMain").style.padding="0px";
  }
}
function kontakt(){
  if(!myEmail(DOLAR("email").value)){
    alert("podaj prawidłowy format email");
    return false;
  }
  if(myTrim(DOLAR("tresc").value)==""){
    alert("wypelnij treść");
    return false;
  }
  if(myTrim(DOLAR("captcha").value)==""){
    alert("przepisz 6 znaków z obrazka");
    return false;
  }
  var req = mint.Request();
  req.OnSuccess = function() {
    if(this.responseText==DOLAR("captcha").value){
      addKontakt();
      refreshCaptcha();
    }
  }
  req.Send("sesja.php5");
}
function addKontakt(){
  var req = mint.Request();
  req.method='POST';
  req.AddParam('email',DOLAR("email").value);
  req.AddParam('tresc',DOLAR("tresc").value);
  req.AddParam('captcha',DOLAR("captcha").value);
  req.OnSuccess = function() {
    DOLAR("email").value="";
    DOLAR("tresc").value="";
   refreshCaptcha();
    alert(this.responseText);
  }
  req.Send("kontakt.php5");
}

$(document).ready(function() {
  onLoad();
});
