function validateFields() {
var frmEl = document.getElementById('cForm');
//var posName = document.getElementById('posName');
var posNev = document.getElementById('posNev');
var posTelefon = document.getElementById('posTelefon');
var posEmail = document.getElementById('posEmail');
var posRegard = document.getElementById('posRegard');
var posProductID = document.getElementById('posProductID');
var posRegard0 = document.getElementById('posRegard0');
var posText = document.getElementById('posText');
//var strCC = document.getElementById('selfCC');
var whiteSpace = /^[\s]+$/;

        if ( posText.value == '' || whiteSpace.test(posText.value) ) {
                alert("Szöveg üres!");
                posText.focus();
        }
        else if ( posNev.value == '' || whiteSpace.test(posNev.value)) {
                alert("Név üres!");
                //alert("I\'m Clearing all the fields!");
                //frmEl.reset();
                //alert("There. Satisified.");
                //alert("Now start over!");
                posNev.focus();
        }
        else if ( posEmail.value == '' && posTelefon.value == '') {
                alert("E-mail cím vagy Telefonszám kitöltendõ!");
                //alert("I\'m Clearing all the fields!");
                //frmEl.reset();
                //alert("There. Satisified.");
                //alert("Now start over!");
                posEmail.focus();
        }
        else {
                sendPosEmail();
        }
}

function sendPosEmail () {
        var success = document.getElementById('emailSuccess');
        var posValindex = document.getElementById('posVal').selectedIndex;
        var posVal = document.getElementById('posVal').options[posValindex].value;
        var posEmail = document.getElementById('posEmail');
        var posTelefon = document.getElementById('posTelefon');
        var posNev = document.getElementById('posNev');
        var posText = document.getElementById('posText');
        var posRegard = document.getElementById('posRegard');
        var posRegard0 = document.getElementById('posRegard0');
        var posProductID = document.getElementById('posProductID').value;
        var page = "/scripts/xmlHttpRequest.php?contact=true&xml=true";
        
        showContactTimer(); // quickly begin the load bar
        success.style.display = 'none'; // hide the success bar (incase this is a multi-email
        
        // convert (&, +, =) to string equivs. Needed so URL encoded POST won't choke.
        var str20 = posTelefon.value;
        str20 = str20.replace(/&/g,"**am**");
        str20 = str20.replace(/=/g,"**eq**");
        str20 = str20.replace(/\+/g,"**pl**");
        var str2 = posEmail.value;
        str2 = str2.replace(/&/g,"**am**");
        str2 = str2.replace(/=/g,"**eq**");
        str2 = str2.replace(/\+/g,"**pl**");
        var str3 = posRegard.value;
        str3 = str3.replace(/á/g,"**aa**");
        str3 = str3.replace(/é/g,"**ee**");
        str3 = str3.replace(/í/g,"**ii**");
        str3 = str3.replace(/ó/g,"**oo**");
        str3 = str3.replace(/ö/g,"**ooo**");
        str3 = str3.replace(/õ/g,"**oooo**");
        str3 = str3.replace(/ú/g,"**uu**");
        str3 = str3.replace(/ü/g,"**uuu**");
        str3 = str3.replace(/û/g,"**uuuu**");
        str3 = str3.replace(/&#369;/g,"**uuuu**");
        str3 = str3.replace(/Á/g,"**AA**");
        str3 = str3.replace(/É/g,"**EE**");
        str3 = str3.replace(/Í/g,"**II**");
        str3 = str3.replace(/Ó/g,"**OO**");
        str3 = str3.replace(/Ö/g,"**OOO**");
        str3 = str3.replace(/Õ/g,"**OOOO**");
        str3 = str3.replace(/Ú/g,"**UU**");
        str3 = str3.replace(/Ü/g,"**UUU**");
        str3 = str3.replace(/Û/g,"**UUUU**");
        str3 = str3.replace(/&/g,"**am**");
        str3 = str3.replace(/=/g,"**eq**");
        str3 = str3.replace(/\+/g,"**pl**");
        var str30 = posRegard0.value;
        str30 = str30.replace(/á/g,"**aa**");
        str30 = str30.replace(/é/g,"**ee**");
        str30 = str30.replace(/í/g,"**ii**");
        str30 = str30.replace(/ó/g,"**oo**");
        str30 = str30.replace(/ö/g,"**ooo**");
        str30 = str30.replace(/õ/g,"**oooo**");
        str30 = str30.replace(/ú/g,"**uu**");
        str30 = str30.replace(/ü/g,"**uuu**");
        str30 = str30.replace(/û/g,"**uuuu**");
        str30 = str30.replace(/&#369;/g,"**uuuu**");
        str30 = str30.replace(/Á/g,"**AA**");
        str30 = str30.replace(/É/g,"**EE**");
        str30 = str30.replace(/Í/g,"**II**");
        str30 = str30.replace(/Ó/g,"**OO**");
        str30 = str30.replace(/Ö/g,"**OOO**");
        str30 = str30.replace(/Õ/g,"**OOOO**");
        str30 = str30.replace(/Ú/g,"**UU**");
        str30 = str30.replace(/Ü/g,"**UUU**");
        str30 = str30.replace(/Û/g,"**UUUU**");
        str30 = str30.replace(/&/g,"**am**");
        str30 = str30.replace(/=/g,"**eq**");
        str30 = str30.replace(/\+/g,"**pl**");
        var str5 = posNev.value;
        str5 = str5.replace(/á/g,"**aa**");
        str5 = str5.replace(/é/g,"**ee**");
        str5 = str5.replace(/í/g,"**ii**");
        str5 = str5.replace(/ó/g,"**oo**");
        str5 = str5.replace(/ö/g,"**ooo**");
        str5 = str5.replace(/õ/g,"**oooo**");
        str5 = str5.replace(/ú/g,"**uu**");
        str5 = str5.replace(/ü/g,"**uuu**");
        str5 = str5.replace(/û/g,"**uuuu**");
        str5 = str5.replace(/&#369;/g,"**uuuu**");
        str5 = str5.replace(/Á/g,"**AA**");
        str5 = str5.replace(/É/g,"**EE**");
        str5 = str5.replace(/Í/g,"**II**");
        str5 = str5.replace(/Ó/g,"**OO**");
        str5 = str5.replace(/Ö/g,"**OOO**");
        str5 = str5.replace(/Õ/g,"**OOOO**");
        str5 = str5.replace(/Ú/g,"**UU**");
        str5 = str5.replace(/Ü/g,"**UUU**");
        str5 = str5.replace(/Û/g,"**UUUU**");
        str5 = str5.replace(/&/g,"**am**");
        str5 = str5.replace(/=/g,"**eq**");
        str5 = str5.replace(/\+/g,"**pl**");
        var str4 = posText.value;
        str4 = str4.replace(/á/g,"**aa**");
        str4 = str4.replace(/é/g,"**ee**");
        str4 = str4.replace(/í/g,"**ii**");
        str4 = str4.replace(/ó/g,"**oo**");
        str4 = str4.replace(/ö/g,"**ooo**");
        str4 = str4.replace(/õ/g,"**oooo**");
        str4 = str4.replace(/ú/g,"**uu**");
        str4 = str4.replace(/ü/g,"**uuu**");
        str4 = str4.replace(/û/g,"**uuuu**");
        str4 = str4.replace(/&#369;/g,"**uuuu**");
        str4 = str4.replace(/Á/g,"**AA**");
        str4 = str4.replace(/É/g,"**EE**");
        str4 = str4.replace(/Í/g,"**II**");
        str4 = str4.replace(/Ó/g,"**OO**");
        str4 = str4.replace(/Ö/g,"**OOO**");
        str4 = str4.replace(/Õ/g,"**OOOO**");
        str4 = str4.replace(/Ú/g,"**UU**");
        str4 = str4.replace(/Ü/g,"**UUU**");
        str4 = str4.replace(/Û/g,"**UUUU**");
        str4 = str4.replace(/&/g,"**am**");
        str4 = str4.replace(/=/g,"**eq**");
        str4 = str4.replace(/\+/g,"**pl**");
        
        var stuff = "posVal="+posVal+"&posProductID="+posProductID+"&posEmail="+str2+"&posTelefon="+str20+"&posNev="+str5+"&posRegard="+str3+"&posRegard0="+str30+"&posText="+str4;
        loadXMLPosDoc(page,stuff)
}

function showContactTimer () {
        var loader = document.getElementById('loadBar');
        loader.style.display = 'block';
        sentTimer = setTimeout("hideContactTimer()",6000);
}

function hideContactTimer () {
        var loader = document.getElementById('loadBar');
        var success = document.getElementById('emailSuccess');
        var fieldArea = document.getElementById('contactFormArea');
        var inputs = fieldArea.getElementsByTagName('input');
        var inputsLen = inputs.length;
        var tAreas = fieldArea.getElementsByTagName('textarea');
        var tAreasLen = tAreas.length;
        var successText = grabPosXML("confirmation");
        successText = successText.replacestring("**am**","&");
        successText = successText.replacestring("**eq**","=");
        successText = successText.replacestring("**pl**","\+");
        // Hide the load bar alas! Done Loading
        loader.style.display = "none";
        success.style.display = "block";
        success.innerHTML = '<strong style="color:lightgreen;">'+successText+'</strong>';
        // Now Hijack the form elements
        for ( i=0;i<inputsLen;i++ ) {
                if ( inputs[i].getAttribute('type') == 'text' ) {
                        inputs[i].value = '';
                }
        }
        for ( j=0;j<tAreasLen;j++ ) {
                tAreas[j].value = '';
        }
}

function ajaxContact() {
var frmEl = document.getElementById('cForm');
addEvent(frmEl, 'submit', validateFields, false);
frmEl.onsubmit = function() { return false; }
}
addEvent(window, 'load',ajaxContact, false);

String.prototype.replacestring = function(from, to) {
return this.split(from).join(to);
}
