var idgl = 0;

function Trim(TRIM_VALUE){

  if(TRIM_VALUE.length < 1){return"";}

  TRIM_VALUE = RTrim(TRIM_VALUE);

  TRIM_VALUE = LTrim(TRIM_VALUE);

  if(TRIM_VALUE==""){return "";}

  else{return TRIM_VALUE;}

} //End Function



function RTrim(VALUE){

  var w_space = String.fromCharCode(32);

  var v_length = VALUE.length;

  var strTemp = "";

  if(v_length < 0){return"";}

  var iTemp = v_length -1;



  while(iTemp > -1){

    if(VALUE.charAt(iTemp) == w_space){

    }

    else{

      strTemp = VALUE.substring(0,iTemp +1);

      break;

    }

    iTemp = iTemp-1;

  } //End While

  return strTemp;

} //End Function



function LTrim(VALUE){

  var w_space = String.fromCharCode(32);

  if(v_length < 1){return"";}

  var v_length = VALUE.length;

  var strTemp = "";



  var iTemp = 0;



  while(iTemp < v_length){

    if(VALUE.charAt(iTemp) == w_space){

    }

    else{

      strTemp = VALUE.substring(iTemp,v_length);

      break;

    }

    iTemp = iTemp + 1;

  } //End While

  return strTemp;

} //End Function



function showDiv(_id){

 x=document.getElementById(_id).style;

 x.display='block';

}

function hideDiv(_id){

 x=document.getElementById(_id).style;

 x.display='none';

}



/*

function OtworzOkno(url,windowName,windowWidth,windowHeight) {

 elements="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width="+windowWidth+",height="+windowHeight+",top="+(window.screen.height-parseInt(windowHeight))/2+",left="+(window.screen.width-parseInt(windowWidth))/2;

 window.open(url,windowName,elements);

}

*/



function OtworzOkno(url,windowName,windowWidth,windowHeight) {

	

	windowHeight = parseInt(windowHeight) + 20;

	var container = document.createElement("div");

	container.onselectstart = new Function("return false");

	idgl = windowName;

	container.setAttribute("id",idgl);

	container.style.position = "absolute";

	container.style.display = "none";

	container.style.width = windowWidth + 'px';

	container.style.height = windowHeight + 'px';

	container.style.background = '#fff';

	container.style.border = '1px solid black';

	container.zIndex=20;

	container.innerHTML= '<div style="text-align:right;"><a href="#" onclick="close_win_pop(\''+idgl+'\')">Zamknij</a></div><iframe name="kurs" id="okno_kursu" src="' + url + '" height="100%" width="100%" frameborder="0"></iframe>';

	if(!document.getElementById("center_content")) return;

	document.getElementById("center_content").appendChild(container);

	moveWindowToCenter(idgl, windowWidth, windowHeight);

	

	

}



function generateId(d){
		var id = "window" + d.getSeconds() + d.getMilliseconds();
		while(document.getElementById(id)) { id += "1"; }
		return id;
}

function close_win_pop(id) {

	var el = document.getElementById(id);
	el.style.display = "none";
	el.id =  generateId(new Date);
	reload_kursy();
}



function moveWindowToCenter(id, sz, wy)

{

	var temp = document.getElementById(id);

/*	var temp_top =  ( ( getScrollY() + (getScreenSize("height") / 2) ) - (wy/2) );
	
	temp.style.top = (temp_top + 30) + "px";

	temp.style.left = ( (getScreenSize("width") / 2) - (sz/2) ) + "px";*/

	temp.style.top = 10 + "px";

	temp.style.left = 10 + "px";
	
	temp.style.display = "block";

}





function getScrollY()

{

	return parseInt( window.pageYOffset ? window.pageYOffset :

	( document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) - 20 );

}



function getScreenSize(mode)

{

	if (self.innerHeight)

	{

		if(mode == 'width') return self.innerWidth;

		else return self.innerHeight;

	}

	else if (document.body)

	{

		if(mode == 'width') return ( document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth );

		else return  document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;

	}

	return 0;

}


function reload_kursy () {

	var element =  document.getElementById('kursy_dla_kazdego_content');

	advAJAX.get({

    url: "/index_kursy_ajax.php",

    onSuccess : function(obj) { element.innerHTML = obj.responseText; },

    onError : function(obj) { alert("Error: " + obj.status); }

   
});

}


