function ajax_post(worker, ertek)
{
	var xmlhttp;
	if (window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	/*xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
			alert(xmlhttp.responseText);
		}
	}*/
	xmlhttp.open("POST", worker, true);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlhttp.send(ertek);
}

function LoginUser() {
    
    if (window.XMLHttpRequest){
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else{
        // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    } 
   
    /*xmlhttp.open( "GET","http://localhost/Hobbikert/megvagy.php", true);
    xmlhttp.send();*/
    
    xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
            message = "";
            error = true;
            response = xmlhttp.responseText;
            type = response;
            if(response == '1' || response == '2' || response == '3' || response == '4' || response == '5' || response != '') {
                switch(response) {
                    case '1': {
                        message = "A felhasználónév és jelszó mező nincs kitöltve!";
                        drawMessage(message,error);
                        break;
                    }
                    case '2': {
                        message = "A felhasználónév mező nincs kitöltve!";
                        drawMessage(message,error);
                        break;
                    }
                    case '3': {
                        message = "A jelszómező nincs kitöltve!";
                        drawMessage(message,error);
                        break;
                    }
                    case '4': {
                        message = "A felhasználónév vagy jelszó nem megfelelő!";
                        drawMessage(message,error);
                        break;
                    }
                    case '5': {
                        message = "Ön még nem aktiválta regisztrációját!";
                        drawMessage(message,error);
                        break;
                    }
                    default : {
                        error = false;
                        message = response;
                        drawMessage(message,error);
                        break;
                    }
                }
            }
		}
	} 
    
    //xmlHttp.open("POST", "http://localhost/Hobbikert/megvagy.php", true);
    //xmlHttp.onreadystatechange = handleRequestStateChange;
    account = document.getElementById('acc');
    acc = account.value;
    password = document.getElementById('pass');
    pass = password.value;
      
    xmlhttp.open( "GET","php/Login.php?acc="+acc+"&pass="+pass, true);
    xmlhttp.send();
}

function drawMessage(message,error) {
   themessage = "";
   if(error == true) {
        themessage = 
            "<div id='messagelayer'>"+
            "<div id='form_layer'>"+
               "<div id='form_line'>"+
                    "<div id='form_box'>"+
                        "<div id='form_box_top'>"+
                            "<div id='form_caption_bg_alert'>"+
                                "<div id='form_caption_icon_alert'></div>"+
                                "<div id='form_caption_text'>Hiba!</div>"+
                                "<div id='form_caption_close' onclick='hideForm()'></div>"+
                            "</div>"+
                        "</div>"+
                        "<div id='form_box_middle'>"+
                            "<div id='form_box_text'>"+message+"</div>"+
                        "</div>"+
                        "<div id='form_box_bottom'></div>"+
                    "</div>"+
                "</div>"+
            "</div>"+
            "</div>";
            document.getElementById('messagelayer').innerHTML = themessage;
            initForm();
        	drawForm();
    }else{
        themessage = 
            "<div id='messagelayer'>"+
            "<div id='form_layer'>"+
               "<div id='form_line'>"+
                    "<div id='form_box'>"+
                        "<div id='form_box_top'>"+
                            "<div id='form_caption_bg_good'>"+
                                "<div id='form_caption_icon_good'></div>"+
                                "<div id='form_caption_text'>Sikeres belépés</div>"+
                                "<div id='form_caption_close' onclick='hideForm()'></div>"+
                            "</div>"+
                        "</div>"+
                        "<div id='form_box_middle'>"+
                            "<div id='form_box_text'>"+message+"</div>"+
                        "</div>"+
                        "<div id='form_box_bottom'></div>"+
                    "</div>"+
                "</div>"+
            "</div>"+
            "</div>";
            acc = message;
            message = "<div id='logged_in'>Bejelentkezve:</div>";
            if(acc == 'admin') {
                message += "<div id='logged_user'><a href='http://hobbikert.com/admin/admin.php'>"+acc+"</a></div>";    
            }else{
                message += "<div id='logged_user'>"+acc+"</div>";    
            }
            message += "<div id='logging_out'> <a href='php/Logout.php'>Kijelentkezés </a> </div>";
            document.getElementById('LoginBox').innerHTML = message;
            //alert(themessage);
    } 
}

function Registration() {
    form = 
        "<div id='messagelayer'>"+
            "<div id='form_layer'>"+
               "<div id='form_line'>"+
                    "<div id='form_box'>"+
                        "<div id='form_box_top'>"+
                            "<div id='form_caption_bg_form'>"+
                                "<div id='form_caption_icon_form'></div>"+
                                "<div id='form_caption_text'>Regisztráció</div>"+
                                "<div id='form_caption_close' onclick='hideForm()'></div>"+
                            "</div>"+
                        "</div>"+
                        "<div id='form_box_middle'>"+
                            "<div id='form_box_text'>"+
                            "<div id='errors'></div>"+
                                "<table>"+
                                    "<tr>"+
                                        "<td class='text'>"+
                                            "Felhasználónév: "+
                                        "<td>"+
                                        "<td>"+
                                            "<input type='text' id='UserName' size='15' onkeyup=\"this.value = this.value.replace(/[^0-9A-Za-z]/g, '')\"/>"+
                                        "<td>"+
                                    "</tr>"+
                                    "<tr>"+
                                        "<td class='text'>"+
                                            "E-mail cím: "+
                                        "<td>"+
                                        "<td>"+
                                            "<input type='text' id='Email' size='30' onkeyup=\"this.value = this.value.replace(/[^0-9A-Za-z@._-]/g, '')\"/>"+
                                        "<td>"+
                                    "</tr>"+
                                    "<tr>"+
                                        "<td class='text'>"+
                                            "Jelszó:"+
                                        "<td>"+
                                        "<td>"+
                                            "<input type='password' id='Pass1' size='15' onkeyup=\"this.value = this.value.replace(/[^0-9A-Za-z]/g, '')\"/>"+
                                        "<td>"+
                                    "</tr>"+
                                    "<tr>"+
                                        "<td class='text'>"+
                                            "Jelszó mégegyszer:"+
                                        "<td>"+
                                        "<td>"+
                                            "<input type='password' id='Pass2' size='15' onkeyup=\"this.value = this.value.replace(/[^0-9A-Za-z]/g, '')\"/>"+
                                        "<td>"+
                                    "</tr>"+
                                        "<tr><td class='caption'>Személyes adatok</td></tr>"+
                                        "<tr>"+
                                            "<td class='text'>"+
                                                "Név:"+
                                            "<td>"+
                                            "<td>"+
                                                "<input type='text' id='Name' size='30' onkeyup=\"this.value = this.value.replace(/[^A-ZÓÜÖÚŐŰÁÉÍa-zóüöúőűáéí ]/g, '')\"/>"+
                                            "<td>"+
                                        "<tr>"+
                                            "<td class='text'>"+
                                                "Telefonszám:"+
                                            "<td>"+
                                            "<td>"+
                                                "<input type='text' id='Phone' size='15' onkeyup=\"this.value = this.value.replace(/[^0-9-+]/g, '')\"/>"+
                                            "<td>"+
                                        "</tr>"+
                                        "<tr>"+
                                            "<td class='text'>"+
                                                "Város:"+
                                            "<td>"+
                                            "<td>"+
                                                "<input type='text' id='City' size='15' onkeyup=\"this.value = this.value.replace(/[^A-ZÓÜÖÚŐŰÁÉÍa-zóüöúőűáéí]/g, '')\"/>"+
                                            "<td>"+
                                        "</tr>"+
                                        "<tr>"+
                                            "<td class='text'>"+
                                                "Irányítószám:"+
                                            "<td>"+
                                            "<td>"+
                                                "<input type='text' id='Zip' size='5' onkeyup=\"this.value = this.value.replace(/[^0-9]/g, '')\"/>"+
                                            "<td>"+
                                        "</tr>"+
                                        "<tr>"+
                                            "<td class='text'>"+
                                                "Közterület:"+
                                            "<td>"+
                                            "<td>"+
                                                "<input type='text' id='StreetName' size='15' onkeyup=\"this.value = this.value.replace(/[^A-ZÓÜÖÚŐŰÁÉÍa-zóüöúőűáéí ]/g, '')\"/><select id='StreetType'><option value='0' selected='selected'>Utca</option><option value='1'>Út</option><option value='2'>Krt.</option><option value='3'>Tér</option></select>"+
                                            "<td>"+
                                        "</tr>"+
                                        "<tr>"+
                                            "<td class='text'>"+
                                                "Házszám:"+
                                            "<td>"+
                                            "<td>"+
                                                "<input type='text' id='HouseNumber' size='15' onkeyup=\"this.value = this.value.replace(/[^0-9a-z ./\]/g, '')\"/>"+
                                            "<td>"+
                                        "</tr>"+
                                        "<tr>"+
                                            "<td class='important'>"+
                                                "Minden mező kitöltése kötelező!"+
                                            "<td>"+
                                        "</tr>"+
                                "</table>"+
                                "<div id='registration_button' onclick='checkRegistrationDatas();'><div id='registration_button_text'>Regisztráció</div></div>"+
                            "</div>"+
                        "</div>"+
                        "<div id='form_box_bottom'></div>"+
                    "</div>"+
                "</div>"+
            "</div>"+
            "</div>";
            document.getElementById('messagelayer').innerHTML = form;
            initForm();
        	drawForm();
}

function checkRegistrationDatas() {
    username = document.getElementById('UserName').value;
    email = document.getElementById('Email').value;
    password1 = document.getElementById('Pass1').value;
    password2 = document.getElementById('Pass2').value;
    s = removeSpaces(document.getElementById('Name').value);
    if(s != false) {
        name = s;    
    }else{ name=""; }
    tel = document.getElementById('Phone').value;
    city = document.getElementById('City').value;
    zipcode = document.getElementById('Zip').value;
    s = removeSpaces(document.getElementById('StreetName').value);
    if(s != false) {
        streetname = s;    
    }else{ streetname=""; }
    streettype = document.getElementById('StreetType').value;
    s = removeSpaces(document.getElementById('HouseNumber').value);
    if(s != false) {
        housenumber = s;    
    }else{ housenumber=""; }
    
    if (window.XMLHttpRequest){
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else{
        // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    } 
    
    xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
		  response = xmlhttp.responseText;
          if(response != "" && response != "%") {
            //hiba
            $('#form_line').css('height',442);  
            $('#form_box').css('height',442);  
            $('#form_box_middle').css('height',382);  
            $('#form_box_text').css('height',372); 
            windowheight = $('#form_layer').height();    
            formheight = $('#form_line').height();
            new_top = (windowheight - formheight) / 2;
            $('#form_line').css('top',new_top);
            
            document.getElementById('errors').innerHTML = response;
            
            height = $('#errors').height();
            form_lineheight = $('#form_line').height();
            form_boxheight = $('#form_box').height();
            form_box_middleheight = $('#form_box_middle').height();
            form_box_textheight = $('#form_box_text').height();
            new_form_lineheight = height+form_lineheight;
            new_form_boxheight = height+form_boxheight;
            new_form_box_middleheight = height+form_box_middleheight;
            new_form_box_textheight = height+form_box_textheight;
            
            $('#form_line').css('height',new_form_lineheight);  
            $('#form_box').css('height',new_form_boxheight);  
            $('#form_box_middle').css('height',new_form_box_middleheight);  
            $('#form_box_text').css('height',new_form_box_textheight); 

            top = $('#form_line').css('top');
            top = top.substring(0,top.length-2);
            new_top = top-(height/2);
            $('#form_line').css('top',new_top); 
          }else if(response == "%"){
            //sikeres rewgistráció
            hideForm();
            caption = "Sikeres regisztráció!";
            text = "Regisztrációját véglegesítheti az ön e-mail címére küldött levélben található aktiváló linkre kattintva!";
            good(caption,text);
          }
		}
	} 
    
    xmlhttp.open( "GET","php/checkRegistrationDatas.php?username="+username+"&pass1="+password1+"&pass2="+password2+"&email="+email+"&name="+name+"&tel="+tel+"&city="+city+"&zip_code="+zipcode+"&streetname="+streetname+"&streettype="+streettype+"&housenumber="+housenumber, true);
    xmlhttp.send();
}

function removeSpaces(value) {
    while(value[0] == " " && value.length != 0) {
        value = value.substring(1,value.length);
    }
    while(value[value.length-1] == " " && value.length != 0) {
        value = value.substring(0,value.length-2);
    }
    if(value.length != 0) {
        return value;    
    }else{
        return false;
    }
}

function insertProduct(id,number) {
    if (window.XMLHttpRequest){
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else{
        // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    } 
    
    xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
		  response = xmlhttp.responseText;
          document.getElementById('basket_products').innerHTML = response;
          reWritePrDisplay();
		}
	} 
    
    
    darabszam = document.getElementById('product_'+id);
    if(darabszam == null) {
        number = 1;
    }else{
        number = darabszam.value;    
    }
    
    xmlhttp.open( "GET","php/Cart.php?id="+id+"&number="+number, true);
    xmlhttp.send();    
}

function reWritePrDisplay() {
    if (window.XMLHttpRequest){
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else{
        // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    } 
    
    xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
		  response = xmlhttp.responseText;
          document.getElementById('basket_pr_display').innerHTML =  "<span>"+response+"</span> termék";
          reWriteCostDisplay();
		}
	} 
      
    xmlhttp.open( "GET","php/Cart.php?reWritePrDisplay", true);
    xmlhttp.send();
}

function dropAllProduct() {
    if (window.XMLHttpRequest){
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else{
        // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    } 
    
    xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
		  text = "<div class='basket_product'>\n"+
                 "<div class='product'></div>\n"+
                 "<div class='db'>-</div>\n"+
                 "<div class='cost'>-</div>\n"+
                 "</div>\n";
          document.getElementById('basket_products').innerHTML = text;
          document.getElementById('basket_pr_display').innerHTML = "<span>0</span> termék";
          document.getElementById('basket_cost').innerHTML = '0 Ft';
		}
	} 
      
    xmlhttp.open( "GET","php/Cart.php?dropallproduct", true);
    xmlhttp.send();
}

function dropProduct(id) {
    if (window.XMLHttpRequest){
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else{
        // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    } 
    
    xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
		  text = xmlhttp.responseText;
          document.getElementById('basket_products').innerHTML = text;
          reWritePrDisplay();
		}
	} 
      
    xmlhttp.open( "GET","php/Cart.php?dropproduct="+id, true);
    xmlhttp.send();
}

function reWriteCostDisplay() {
    if (window.XMLHttpRequest){
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else{
        // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    } 
    
    xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
		  text = xmlhttp.responseText;
          document.getElementById('basket_cost').innerHTML = text+' Ft';
		}
	} 
      
    xmlhttp.open( "GET","php/Cart.php?reWriteCostDisplay", true);
    xmlhttp.send();
}

function reWriteMiniBasket() {
    text = "<div class='basket_product'>\n"+
                "<div class='product'></div>\n"+
                "<div class='db'>-</div>\n"+
                "<div class='cost'>-</div>\n"+
            "</div>\n";
    document.getElementById('basket_products').innerHTML = text;
}

function rapidSearch() {
    if (window.XMLHttpRequest){
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else{
        // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    } 
    text = "";
    themessage = "";
    xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
		  text = xmlhttp.responseText;
              if(text == "") {
                caption = "Keresés";
                text = "A keresés nem hozott eredményt.";
                information(caption,text);      
              }else{
                //header("Location: ../index.php?page=webshop");
                //rapidfilter = document.getElementById('rapidfilter').value;
                window.location = 'http://hobbikert.com/index.php?page=webshop&'+rapidfilter+'#filters';
              }
		}
	} 
      
    //ÜRESKARAKTEREK SZŰRÉSE!!!
    rapidfilter = document.getElementById('rapidfilter').value;
    rapidfilter = removeSpaces(rapidfilter);
    if(rapidfilter.length < 3 || rapidfilter == false) {
        caption = "Keresés";
        text = "A kereséshez legalább 3 karaktert meg kell adni!";
        warning(caption,text);
    }else{
        xmlhttp.open( "GET","php/search.php?filtervalue="+rapidfilter, true);
        xmlhttp.send();  
    }
}

function rapidSearchE(e) {
    if (window.event) { e = window.event; }
                if (e.keyCode == 13)
                {
                        //rapidSearch();
                        alert("asd");
                }    
                alert("asd");
}

function lostPass() {
    caption = "Elfelejtett jelszó";
    text = "Fejlesztés alatt.";
    warning(caption,text);
}

function sendOrder() {
    if (window.XMLHttpRequest){
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else{
        // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    } 
    
    xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
		  text = xmlhttp.responseText;
          switch(text) {
            case '0': {
                message = 'A kosár üres!';
                drawMessage(message,true);
                break;
            }
            case '1': {
                //Megrenedéshez szükséges adatok
                form = 
                "<div id='messagelayer'>"+
                    "<div id='form_layer'>"+
                       "<div id='form_line'>"+
                            "<div id='form_box'>"+
                                "<div id='form_box_top'>"+
                                    "<div id='form_caption_bg_form'>"+
                                        "<div id='form_caption_icon_form'></div>"+
                                        "<div id='form_caption_text'>Megrendelés</div>"+
                                        "<div id='form_caption_close' onclick='hideForm()'></div>"+
                                    "</div>"+
                                "</div>"+
                                "<div id='form_box_middle'>"+
                                    "<div id='form_box_text'>"+
                                    "<div id='errors'></div>"+
                                        "<table>"+
                                                "<tr>"+
                                                    "<td>"+
                                                        "<select onChange='changeRMode(this)'><option>DPD futár</option><option selected='selected'>Személyes átvétel</option></select><input type='hidden' id='rmode' value='2'/>"+
                                                    "</td>"+
                                                "</tr>"+
                                        "</table>"+
                                        "<div id='registration_button' onclick='send1()'><div id='registration_button_text'>Rendelés</div></div>"+
                                    "</div>"+
                                "</div>"+
                                "<div id='form_box_bottom'></div>"+
                            "</div>"+
                        "</div>"+
                    "</div>"+
                    "</div>";
                    document.getElementById('messagelayer').innerHTML = form;
                    initForm();
                	drawForm();
                break;
            }
            case '2': {
                //Megrenedéshez szükséges adatok
                form = 
                "<div id='messagelayer'>"+
                    "<div id='form_layer'>"+
                       "<div id='form_line'>"+
                            "<div id='form_box'>"+
                                "<div id='form_box_top'>"+
                                    "<div id='form_caption_bg_form'>"+
                                        "<div id='form_caption_icon_form'></div>"+
                                        "<div id='form_caption_text'>Megrendelés</div>"+
                                        "<div id='form_caption_close' onclick='hideForm()'></div>"+
                                    "</div>"+
                                "</div>"+
                                "<div id='form_box_middle'>"+
                                    "<div id='form_box_text'>"+
                                    "<div id='errors'></div>"+
                                        "<table>"+
                                                "<tr><td class='captionf'>Adatok</td></tr>"+
                                                "<tr>"+
                                                    "<td class='text'>"+
                                                        "Név:"+
                                                    "<td>"+
                                                    "<td>"+
                                                        "<input type='text' id='Name' size='30' onkeyup=\"this.value = this.value.replace(/[^A-ZÓÜÖÚŐŰÁÉÍa-zóüöúőűáéí ]/g, '')\"/>"+
                                                    "<td>"+
                                                "<tr>"+
                                                    "<td class='text'>"+
                                                        "E-mail cím: "+
                                                    "<td>"+
                                                    "<td>"+
                                                        "<input type='text' id='Email' size='30' onkeyup=\"this.value = this.value.replace(/[^0-9A-Za-z@._-]/g, '')\"/>"+
                                                    "<td>"+ 
                                                "</tr>"+
                                                "<tr>"+
                                                    "<td class='text'>"+
                                                        "Telefonszám:"+
                                                    "<td>"+
                                                    "<td>"+
                                                        "<input type='text' id='Phone' size='15' onkeyup=\"this.value = this.value.replace(/[^0-9-+]/g, '')\"/>"+
                                                    "<td>"+
                                                "</tr>"+
                                                "<tr>"+
                                                    "<td class='text'>"+
                                                        " "+
                                                    "<td>"+
                                                    "<td>"+
                                                        "<select id='mode' onChange='changeTMode(this)'><option>DPD futár</option><option selected='selected'>Személyes átvétel</option></select><input type='hidden' id='tmode' value='2'/>"+
                                                    "</td>"+
                                                "</tr>"+
                                        "</table>"+
                                        "<div id='adressorder'>"+
                                        "</div>"+
                                        "<div id='registration_button' onclick='send2()'><div id='registration_button_text'>Rendelés</div></div>"+
                                    "</div>"+
                                "</div>"+
                                "<div id='form_box_bottom'></div>"+
                            "</div>"+
                        "</div>"+
                    "</div>"+
                    "</div>";
                    document.getElementById('messagelayer').innerHTML = form;
                    initForm();
                	drawForm();
                    break;
            }
          }
		}
	}     
    xmlhttp.open( "GET","php/Order.php", true);
    xmlhttp.send();
}

function send1(){
    if (window.XMLHttpRequest){
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else{
        // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    } 
    
    rmode = document.getElementById('rmode').value;
    
    xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
		  text = xmlhttp.responseText;
          if(text == '3') {
            hideForm();
            initForm();
            caption = "Sikeres megrendelés!";
            text = "A megrendelését véglegelsítheti, az ön e-mail címére küldött levélben található aktiváló linkre kattintva.";
            good(caption,text);
            reWriteCostDisplay();
            reWriteMiniBasket();
            reWritePrDisplay();
          }else{
            text = "Sikertelen megrendelés...";
            drawMessage(text,true);
            reWriteCostDisplay();
            reWriteMiniBasket();
            reWritePrDisplay();
          }
		}
	}  
    xmlhttp.open( "GET","php/Order.php?rmode="+rmode, true);
    xmlhttp.send();
}

function send2(){
    if (window.XMLHttpRequest){
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else{
        // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    } 
    
    tmode = document.getElementById('tmode').value;
    
    xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
		  text = xmlhttp.responseText;
          if(text == '3') {
            //sikeres megrendelés
                hideForm();
                initForm();
                caption = "Sikeres megrendelés!";
                text = "A megrendelését véglegelsítheti, az ön e-mail címére küldött levélben található aktiváló linkre kattintva.";
                good(caption,text);
                reWriteCostDisplay();
                reWriteMiniBasket();
                reWritePrDisplay();
          }else{
            //hiba
            document.getElementById('errors').innerHTML = text;
            height = $('#errors').height();
            if(tmode == 1){
                //Dpd
                $('#form_line').css('height',392);  
                $('#form_box').css('height',392);  
                $('#form_box_middle').css('height',332);  
                $('#form_box_text').css('height',322); 
            }else{
                //személyes
                $('#form_line').css('height',252);  
                $('#form_box').css('height',252);  
                $('#form_box_middle').css('height',192);  
                $('#form_box_text').css('height',182); 
                
            }
            windowheight = $('#form_layer').height();    
            formheight = $('#form_line').height();
            new_top = (windowheight - formheight) / 2;
            $('#form_line').css('top',new_top);
            
            form_lineheight = $('#form_line').height();
            form_boxheight = $('#form_box').height();
            form_box_middleheight = $('#form_box_middle').height();
            form_box_textheight = $('#form_box_text').height();
            new_form_lineheight = height+form_lineheight;
            new_form_boxheight = height+form_boxheight;
            new_form_box_middleheight = height+form_box_middleheight;
            new_form_box_textheight = height+form_box_textheight;
            
            $('#form_line').css('height',new_form_lineheight);  
            $('#form_box').css('height',new_form_boxheight);  
            $('#form_box_middle').css('height',new_form_box_middleheight);  
            $('#form_box_text').css('height',new_form_box_textheight); 

            top = $('#form_line').css('top');
            top = top.substring(0,top.length-2);
            new_top = top-(height/2);
            $('#form_line').css('top',new_top);
          }
		}
	} 
    
    name = document.getElementById('Name').value;
    email = document.getElementById('Email').value;
    tel = document.getElementById('Phone').value;
    if(tmode == 1) {
        //DPD futár
        city = document.getElementById('City').value;
        zip = document.getElementById('Zip').value;
        streetname = document.getElementById('StreetName').value;
        streettype = document.getElementById('StreetType').value;
        housenumber = document.getElementById('HouseNumber').value;
        xmlhttp.open( "GET","php/Order.php?tmode="+tmode+"&name="+name+"&email="+email+"&tel="+tel+"&city="+city+"&zip_code="+zip+"&streetname="+streetname+"&streettype="+streettype+"&housenumber="+housenumber, true);
    }else{
        //Személyes átvétel
        xmlhttp.open( "GET","php/Order.php?tmode="+tmode+"&name="+name+"&email="+email+"&tel="+tel, true);
    }
    xmlhttp.send();
}

function changeRMode(selectobj) {
    option = selectobj.selectedIndex+1;
    document.getElementById('rmode').value = option;
}

function changeTMode(selectobj) {
    option = selectobj.selectedIndex+1;
    document.getElementById('tmode').value = option;
    form = "";
    errorheight = $('#errors').height();
    if(option == 1) {
        //személyes átvétel
            $('#form_line').css('height',(392+errorheight));  
            $('#form_box').css('height',(392+errorheight));  
            $('#form_box_middle').css('height',(332+errorheight));  
            $('#form_box_text').css('height',(322+errorheight)); 
            windowheight = $('#form_layer').height();    
            formheight = $('#form_line').height();
            new_top = (windowheight - formheight) / 2;
            $('#form_line').css('top',new_top);
        //
        
        document.getElementById('adressorder').innerHTML = 
                                            "<table>"+
                                                "<tr>"+
                                                    "<td class='text'>"+
                                                        "Város:"+
                                                    "<td>"+
                                                    "<td>"+
                                                        "<input type='text' id='City' size='15' onkeyup=\"this.value = this.value.replace(/[^A-ZÓÜÖÚŐŰÁÉÍa-zóüöúőűáéí]/g, '')\"/>"+
                                                    "<td>"+
                                                "</tr>"+
                                                "<tr>"+
                                                    "<td class='text'>"+
                                                        "Irányítószám:"+
                                                    "<td>"+
                                                    "<td>"+
                                                        "<input type='text' id='Zip' size='5' onkeyup=\"this.value = this.value.replace(/[^0-9]/g, '')\"/>"+
                                                    "<td>"+
                                                "</tr>"+
                                                "<tr>"+
                                                    "<td class='text'>"+
                                                        "Közterület:"+
                                                    "<td>"+
                                                    "<td>"+
                                                        "<input type='text' id='StreetName' size='15' onkeyup=\"this.value = this.value.replace(/[^A-ZÓÜÖÚŐŰÁÉÍa-zóüöúőűáéí ]/g, '')\"/><select id='StreetType'><option value='0' selected='selected'>Utca</option><option value='1'>Út</option><option value='2'>Krt.</option><option value='3'>Tér</option></select>"+
                                                    "<td>"+
                                                "</tr>"+
                                                "<tr>"+
                                                    "<td class='text'>"+
                                                        "Házszám:"+
                                                    "<td>"+
                                                    "<td>"+
                                                        "<input type='text' id='HouseNumber' size='15' onkeyup=\"this.value = this.value.replace(/[^0-9a-z ./\]/g, '')\"/>"+
                                                    "<td>"+
                                                "</tr>"+
                                                "<tr>"+
                                                    "<td class='important'>"+
                                                        "Minden mező kitöltése kötelező!"+
                                                    "<td>"+
                                                "</tr>"+
                                        "</table>";
    }else{
        //futár
        document.getElementById('adressorder').innerHTML = "";
            $('#form_line').css('height',(252+errorheight));  
            $('#form_box').css('height',(252+errorheight));  
            $('#form_box_middle').css('height',(192+errorheight));  
            $('#form_box_text').css('height',(182+errorheight)); 
            windowheight = $('#form_layer').height();    
            formheight = $('#form_line').height();
            new_top = (windowheight - formheight) / 2;
            $('#form_line').css('top',new_top);
    }
}

function information( caption, text){
    themessage =  "<div id='messagelayer'>"+
                        "<div id='form_layer'>"+
                           "<div id='form_line'>"+
                                "<div id='form_box'>"+
                                    "<div id='form_box_top'>"+
                                        "<div id='form_caption_bg_information'>"+
                                            "<div id='form_caption_icon_information'></div>"+
                                            "<div id='form_caption_text'>"+caption+"</div>"+
                                            "<div id='form_caption_close' onclick='hideForm()'></div>"+
                                        "</div>"+
                                    "</div>"+
                                    "<div id='form_box_middle'>"+
                                        "<div id='form_box_text'>"+text+"</div>"+
                                    "</div>"+
                                    "<div id='form_box_bottom'></div>"+
                                "</div>"+
                            "</div>"+
                        "</div>"+
                        "</div>";
                        document.getElementById('messagelayer').innerHTML = themessage; 
                        drawForm();
}

function warning( caption, text){
    themessage ="<div id='messagelayer'>"+
                    "<div id='form_layer'>"+
                       "<div id='form_line'>"+
                            "<div id='form_box'>"+
                                "<div id='form_box_top'>"+
                                    "<div id='form_caption_bg_warning'>"+
                                        "<div id='form_caption_icon_warning'></div>"+
                                        "<div id='form_caption_text'>"+caption+"</div>"+
                                        "<div id='form_caption_close' onclick='hideForm()'></div>"+
                                    "</div>"+
                                "</div>"+
                                "<div id='form_box_middle'>"+
                                    "<div id='form_box_text'>"+text+"</div>"+
                                "</div>"+
                                "<div id='form_box_bottom'></div>"+
                            "</div>"+
                        "</div>"+
                    "</div>"+
                    "</div>";
    document.getElementById('messagelayer').innerHTML = themessage;
   	drawForm();
}

function good( caption, text){
    themessage =    "<div id='messagelayer'>"+
                        "<div id='form_layer'>"+
                           "<div id='form_line'>"+
                                "<div id='form_box'>"+
                                    "<div id='form_box_top'>"+
                                        "<div id='form_caption_bg_good'>"+
                                            "<div id='form_caption_icon_good'></div>"+
                                            "<div id='form_caption_text'>"+caption+"</div>"+
                                            "<div id='form_caption_close' onclick='hideForm()'></div>"+
                                        "</div>"+
                                    "</div>"+
                                    "<div id='form_box_middle'>"+
                                        "<div id='form_box_text'>"+text+"</div>"+
                                    "</div>"+
                                    "<div id='form_box_bottom'></div>"+
                                "</div>"+
                            "</div>"+
                        "</div>"+
                        "</div>";
                document.getElementById('messagelayer').innerHTML = themessage;
                initForm();
               	drawForm();
}




