var xmlHttp

function disableEnterKey(e)
{
     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13)
          return false;
     else
          return true;
}
function str_replace(search, replace, subject, count) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Gabriel Paderni
    // +   improved by: Philip Peterson
    // +   improved by: Simon Willison (http://simonwillison.net)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   bugfixed by: Anton Ongson
    // +      input by: Onno Marsman
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    tweaked by: Onno Marsman
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   input by: Oleg Eremeev
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Oleg Eremeev
    // %          note 1: The count parameter must be passed as a string in order
    // %          note 1:  to find a global variable in which the result will be given
    // *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
    // *     returns 1: 'Kevin.van.Zonneveld'
    // *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
    // *     returns 2: 'hemmo, mars'
 
    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }
 
    for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {
            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}
        }
    }
    return sa ? s : s[0];
}
function toggleDiv2(div){
 if ($(div).style.display=='none') {
	$(div).blindDown({ duration: 1 })
 }
 else {
	$(div).blindUp({ duration: 1 })
}
}

function toggleDiv(div){
 if ($(div).style.display=='none') {
	$(div).style.display='block';
 }
 else {
	$(div).style.display='none';
}
}
 

function trackOrder(orderid, trackid)
{ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }
	var url="admin/track_order.php"
	url=url+"?orderid="+orderid+"&trackid="+trackid

	xmlHttp.onreadystatechange=function stateChanged() {stateChangedOK_TRACKING()} 
	xmlHttp.open("GET",url,true)
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8') 
	xmlHttp.send(null)
}

function emailOrder(orderid, userid)
{ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }
	var url="admin/send_confirmation.php"
	url=url+"?orderid="+orderid+"&userid="+userid

	xmlHttp.onreadystatechange=function stateChanged() {stateChangedOK_EMAIL()} 
	xmlHttp.open("GET",url,true)
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8') 
	xmlHttp.send(null)
}

function markOrder(orderid)
{ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }
	var url="admin/mark_order.php"
	url=url+"?orderid="+orderid

	xmlHttp.onreadystatechange=function stateChanged() {stateChangedOK_ORDER(orderid)} 
	xmlHttp.open("GET",url,true)
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8') 
	xmlHttp.send(null)
}

function archiveOrder(orderid)
{ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }
	var url="admin/archive_order.php"
	url=url+"?orderid="+orderid

	xmlHttp.onreadystatechange=function stateChanged() {stateChangedOK_ARCHIVE(orderid)} 
	xmlHttp.open("GET",url,true)
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8') 
	xmlHttp.send(null)
}

function updateOrderStatus(orderid, statusid)
{ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }

	var url="admin/update_order_status.php"
	url=url+"?orderid="+orderid

	xmlHttp.onreadystatechange=function stateChanged() {stateChangedOK_ORDER(orderid)} 
	xmlHttp.open("GET",url,true)
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8') 
	xmlHttp.send(null)
}
function updateAddress(orderid, addressid, element)
{ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }

	var url="ajax_update_address.php"
	url=url+"?orderid="+orderid+"&addressid="+addressid+"&element="+element

	xmlHttp.onreadystatechange=function stateChanged() {stateChangedOK_ADDRESS(element,orderid,0)} 
	xmlHttp.open("GET",url,true)
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8') 
	xmlHttp.send(null)
}
function refreshAddress(orderid, element)
{ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }

	var url="ajax_refresh_address.php"
	var ele;
	var elem;
	
	if (element=="shippingAddress") {
		ele = "billingAddress";
	}
	if (element=="billingAddress") {
		ele = "shippingAddress";
	}
	elem = ele+"Down"
	url=url+"?orderid="+orderid+"&element="+element
	
	xmlHttp.onreadystatechange=function stateChanged() {stateChangedOK_UPDATE_ADDRESS(elem)} 
	xmlHttp.open("GET",url,true)
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8') 
	xmlHttp.send(null)
}

function checkForm(city, address, name, postalcode) {

	if ( city == "" || address == "" || postalcode == "" ){
		alert('Nem töltött ki minden *-al jelölt mezőt!');
		return false;
	}
	else {
		return true;
	}
}

function newAddress(city, address, name, postalcode, taxnumber, orderid, element)
{ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }

	var url="ajax_update_address.php"
	name=str_replace('&','(_amp_)',name)
	city=str_replace('&','(_amp_)',city)
	address=str_replace('&','(_amp_)',address)	
	
	url=url+"?city="+city+"&name="+name+"&address="+address+"&pcode="+postalcode+"&tax="+taxnumber+"&orderid="+orderid+"&element="+element
	url=encodeURI(url)
	
	xmlHttp.onreadystatechange=function stateChanged() {stateChangedOK_ADDRESS(element,orderid,1)} 
	xmlHttp.open("GET",url,true)
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8') 
	xmlHttp.send(null)
}

function rateVideo(videoid, userid, ratenum)
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
var url="rate2.php"
url=url+"?vid="+videoid
url=url+"&userid="+userid
url=url+"&ratenum="+ratenum
xmlHttp.onreadystatechange=function stateChanged() {stateChangedOK(videoid)} 
xmlHttp.open("GET",url,true)
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8') 
xmlHttp.send(null)
}

function stateChangedOK(videoid) 
{
var elementName="txtHint"+videoid
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	document.getElementById(elementName).innerHTML=xmlHttp.responseText 
 }
else if (xmlHttp.readyState<4)
 {
	document.getElementById(elementName).innerHTML='<img src="ajax-loader.gif" />'
 }
 else {
	document.getElementById(elementName).innerHTML='<img src="ajax-loader.gif" />'
 }
}

function stateChangedOK_ORDER(orderid) 
{
var elementName="order"+orderid
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	document.getElementById(elementName).innerHTML=xmlHttp.responseText 
 }
else if (xmlHttp.readyState<4)
 {
 }
 else {
 }
}

function stateChangedOK_ADDRESS(element,orderid,itsnew) 
{
var elementName=element
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 {  
	document.getElementById(elementName).innerHTML=xmlHttp.responseText 
	if (itsnew==1) {
		refreshAddress(orderid,element)
	}
 }
else if (xmlHttp.readyState<4)
 {
 }
 else {
 }
}
function stateChangedOK_UPDATE_ADDRESS(element) 
{
var elementName=element
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 {  
	document.getElementById(elementName).innerHTML=xmlHttp.responseText 
 }
else if (xmlHttp.readyState<4)
 {
 }
 else {
 }
}

function stateChangedOK_TRACKING() 
{
var elementName="tracking"
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	document.getElementById(elementName).innerHTML=xmlHttp.responseText 
 }
else if (xmlHttp.readyState<4)
 {
	document.getElementById(elementName).innerHTML='<img src="ajax-loader.gif" />'
 }
 else {
	document.getElementById(elementName).innerHTML='<img src="ajax-loader.gif" />'
 }
}

function stateChangedOK_EMAIL() 
{
var elementName="email"
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	document.getElementById(elementName).innerHTML=xmlHttp.responseText 
 }
else if (xmlHttp.readyState<4)
 {
	document.getElementById(elementName).innerHTML='<img src="ajax-loader.gif" />'
 }
 else {
	document.getElementById(elementName).innerHTML='<img src="ajax-loader.gif" />'
 }
}

function stateChangedOK_ARCHIVE(orderid) 
{
var elementName="archive"+orderid
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	document.getElementById(elementName).innerHTML=xmlHttp.responseText 
 }
else if (xmlHttp.readyState<4)
 {
 }
 else {
 }
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}


	
	function setOnunload() {

		window.onbeforeunload = exitCheck;
        window.onunload = test;
		
	}
	

	
	function submitFormSkipOnunload() {
        window.onbeforeunload = function() {};
        window.onunload = test;
	}


        function test(){
        }
        function exitCheck(evt){
           return "Még nem küldted el az aktuális oldalt. Ha nem kívánsz menteni, kattints az OK gombra, ha menteni szeretnél a Mégse gombra. Mentéskor küldd el az űrlapot!";
        }
