// AJAX

var request;
var queryString;   //will hold the POSTed data
var calendarId;

function sendData2(melyik,mikor){
    calendarId = melyik;
    queryString = "level=" + calendarId + "&month=" + mikor;
    //alert(queryString);
    var myurl="http://kiadonyaralo.extra.hu/calendar/cal_index.php";
    httpRequest("POST",myurl,true);
}


//event handler for XMLHttpRequest
function handleResponse(  ){
    if(request.readyState == 4){
        if(request.status == 200){
				    //alert(request.responseText);
				    
				   //alert(request.getAllResponseHeaders());
            var doc = request.responseXML;
            var info = request.responseText
            //getDocInfo(doc);
            var container = calendarId + "_cal";
      //      alert(container);
            stylizeDiv(info,document.getElementById(container));
        } else {
            alert("A problem occurred with communicating between the XMLHttpRequest object and the server program.");
        }
    }//end outer if
}

/* Wrapper function for constructing a request object.
 Parameters:
  reqType: The HTTP request type, such as GET or POST.
  url: The URL of the server program.
  asynch: Whether to send the request asynchronously or not. */

function httpRequest(reqType,url,asynch){
    //Mozilla-based browsers
    if(window.XMLHttpRequest){
        request = new XMLHttpRequest(  );
    } else if (window.ActiveXObject){
        request=new ActiveXObject("Msxml2.XMLHTTP");
        if (! request){
            request=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    //the request could still be null if neither ActiveXObject
    //initialization succeeded
    if(request){
        initReq(reqType,url,asynch);
    } else {
        alert("Your browser does not permit the use of all "+
              "of this application's features!");
    }
}
/* Initialize a request object that is already constructed */
function initReq(reqType,url,bool){
    /* Specify the function that will handle the HTTP response */
    request.onreadystatechange=handleResponse; 
		request.open(reqType,url,bool);
    /* Set the Content-Type header for a POST request */
		request.setRequestHeader("Content-Type",
            "application/x-www-form-urlencoded; charset=UTF-8");
    request.send(queryString);
}

/* Provide the div element's content dynamically. We can add
style information to this function if we want to jazz up the div */
function stylizeDiv(bdyTxt,div){
    //reset DIV content
    div.innerHTML="";
    div.innerHTML=bdyTxt;
}

// EGYEB

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImagesArray(array) {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<array.length; i+=2) {
			document[array[i]].src = array[i+1];
		}
	}
}

function changeImages() {
	changeImagesArray(changeImages.arguments);
}

function toggleImages() {
	for (var i=0; i<toggleImages.arguments.length; i+=2) {
		if (selected == toggleImages.arguments[i])      changeImagesArray(toggleImages.arguments[i+1]);
	}
}

var selected = '';
var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		lakas_517 = newImage("images/lakas_517.gif");
		lakas_818 = newImage("images/lakas_818.gif");
		lakas_1119 = newImage("images/lakas_1119.gif");
		lakas_1120 = newImage("images/lakas_1120.gif");
		lakas_1121 = newImage("images/lakas_1121.gif");
		preloadFlag = true;
	}
}


function terkep_nyit() 
{
window.open('terkep.html','','width=471,height=304,resizable=no,directories=no,location=no,menubar=no,scrollbars=no,toolbar=no,titlebar=no,left=200,top=200')
}

function pic_open(fn)
{
 var params='resizable=no,directories=no,location=no,menubar=no,scrollbars=no,toolbar=no,left=100,top=100,width=800,height=600';
 msgWindow = window.open("","",params);
 
  msgWindow.document.writeln("<html>");
 msgWindow.document.writeln("<head><title>Balatoni nyaralo kepek</title>");
  msgWindow.document.writeln("<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>");
 msgWindow.document.writeln("</head>");
 msgWindow.document.writeln("<body topmargin='0' leftmargin='0' marginwidth='0' marginheight='0'>");
  msgWindow.document.writeln("<a href='' onclick='window.self.close()'><img src='"+fn+"' border='0'></a>");
 msgWindow.document.writeln("</body>");
 msgWindow.document.writeln("</html>");
}

function uresCheck(mezo){
  if (mezo.value != "") return true;
  else{
    alert("A(z) "+ mezo.name +" mező üres!");
    return false;
  }
}

function emailCheck(mezo){
  var szoveg = mezo.value;
  if (!(szoveg.indexOf('@')>0 && szoveg.indexOf('@')<szoveg.length-1)){
    alert("Rossz e-mail cím!");
    return false;
  }
  else return true;
}

function ellenoriz(){
  if (uresCheck(document.form.nev) && uresCheck(document.form.email) &&
      emailCheck(document.form.email)){
      	
    document.form.action = "feldolgoz.php";
    return true;
  }
  else return false;
}
