var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
  try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
   try {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
   } catch (E) {
    xmlhttp = false;
   }
  }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}

/**
 * Betölti a településválasztó tartalmát az AJAX lekérésből és
 * beállítja a kiválasztott elemet
 *
 * @param   string      elementID       DOM element azonosítója
 * @param   string      serverURL       Szerver címe
 * @param   Object      sender          Hívó objektum
 */
function loadCities(elementID, serverURL, sender) {
    var categoryID = sender.options[sender.selectedIndex].value;
	var element = document.getElementById(elementID);
    xmlhttp.open("GET", serverURL+"?categoryID="+categoryID, true);
	xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            element.innerHTML = "";
            var options = xmlhttp.responseText;
            optionArray = options.split('\n');
            for (i=0; i<optionArray.length; i++) {
                optionParams = optionArray[i].split("|");
                opt = document.createElement("option");
                opt.value = optionParams[0];
                opt.text = optionParams[1];
                element.options.add(opt);
            }
            for (i=0; i<element.options.length; i++) {
                if (element.options[i].value==placeID) {
                    element.selectedIndex = i;
                    return;
                }
            }
        }
    }
    xmlhttp.send(null);
}

/**
 * Ellenőrző kérdést tesz fel, majd törli a megadott képet
 *
 * @param   string      deleteURL       Törlés URL-je
 */
function deleteImage(deleteURL) {
    if (confirm(confirmImageDelete)) {
        window.location.href=deleteURL;
    }
    return false;
}

/**
 * Ellenőrzi a kötelező adatokat a hirdetés feladása formon
 */
function checkAdvert() {
    if (document.advertForm.placeID.selectedIndex==0) {
        alert(EplaceID);
        document.advertForm.placeID.focus();
        return false;
    } else if (document.advertForm.price.value=="" || document.advertForm.price.value<=0) {
        alert(Eprice);
        document.advertForm.price.focus();
        return false;
    } else if (document.advertForm.area.value=="" || document.advertForm.area.value==0) {
        alert(Earea);
        document.advertForm.area.focus();
        return false;
    } else if (document.advertForm.ad_description.value=="") {
        alert(Edescr);
        document.advertForm.ad_description.focus();
        return false;
    } else if (document.advertForm.ad_phone.value=="") {
        alert(Ephone);
        document.advertForm.ad_phone.focus();
        return false;        
    } else {
        return true;
    }
}

/**
 * Ellenőrzi a kötelező adatokat hirdetéshez hozzászólás esetén
 */
function checkComment() {
    if (document.emailForm.name.value=="") {
        alert(Ename);
        document.emailForm.name.focus();
        return false;
    } else if (!validEmail(document.emailForm.email.value)) {
        alert(Eemail);
        document.emailForm.email.focus();
        return false;
    } else if (document.emailForm.subject.value=="") {
        alert(Esubject);
        document.emailForm.subject.focus();
        return false;
    } else if (document.emailForm.message.value=="") {
        alert(Emessage);
        return false;
    } else if (document.emailForm.turingCode.value=="") {
        alert(EturingCode);
        document.emailForm.turingCode.focus();
        return false;
    } else {
        return true;
    }
}

/**
 * Ellenőrzi a feladott hirdetés hosszát
 */
function checkAdvertLength(textarea, maxLength) {
    document.advertForm.charsLeft.value = maxLength-textarea.value.length;
}