var xmlHttp

function toggleExtended(){
	if ( document.post.ext[1].checked == true ) {
		$('extendedArea').style.display='block';
	}
	else {
		$('extendedArea').style.display='none';
	}
}


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=iso-8859-2') 
	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=iso-8859-2') 
	xmlHttp.send(null)
}

function updateOrderStatus(orderid, statusid)
{ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }
	 alert(orderid+' '+statusid);
	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=iso-8859-2') 
	xmlHttp.send(null)
}


function change(){
 if ($('menu').style.display=='none') {
	showMenu();
 }
 else {
	hideMenu();
 }
}

function changeAnchor(anchor){
 if ($(anchor).innerHTML=='több hír') {
	$(anchor).innerHTML='kevesebb hír';
 }
 else {
	$(anchor).innerHTML='több hír';
 }
}

function hideMenu(){
	$('menu').style.display = 'none';
	$('content').style.marginLeft = '0px';
	$('sideBarToggle').src='images/show.png';
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request")
		return
	}
	 
	var url='ajax_statusbar.php?s=0';
	xmlHttp.onreadystatechange=function stateChanged() {stateChangedOK_status(xmlHttp)} 
	xmlHttp.open("GET",url,true)
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8') 
	xmlHttp.send(null)
}

function showMenu(){
	$('menu').style.display = 'block';
	$('content').style.marginLeft = '200px';
	$('sideBarToggle').src='images/hide.png';
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request")
		return
	}
	 
	var url='ajax_statusbar.php?s=1';
	xmlHttp.onreadystatechange=function stateChanged() {stateChangedOK_status(xmlHttp)} 
	xmlHttp.open("GET",url,true)
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8') 
	xmlHttp.send(null)	
}

function comment(userid, objectid, ccatid, message){
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request")
		return
	}
	 
	var url='ajax_comment.php';
	var params = 'userid='+userid+'&objectid='+objectid+'&ccatid='+ccatid+'&message='+message;
	
	xmlHttp.open("POST",url,true);
	xmlHttp.onreadystatechange = function() {
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
 		$('ajaxLoader').style.display='none';		
		$('leavemycomment').disabled=false;
		if (xmlHttp.responseText!='') alert(xmlHttp.responseText);
		else {
			loadPageAjax('ajax_commentlist.php?ccatid='+ccatid+'&objid='+objectid,'commentlist');
			$('message').value='';	
		}
	}
	else {
 		$('ajaxLoader').style.display='block';	
		$('leavemycomment').disabled=true;
	}
}
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8') 
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");	
	xmlHttp.send(params);
}

function stateChangedOK_status(httpClass) 
{
	if (httpClass.readyState==4 || httpClass.readyState=="complete")
	 { 
	 }

}

function loadPageAjax(page, div)
{ 

	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }
	 
	var url=page;

	xmlHttp.onreadystatechange=function stateChanged() {stateChangedOK2(div,xmlHttp)} 
	xmlHttp.open("GET",url,true)
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8') 
	xmlHttp.send(null)
			
}

function toggleDiv2(div){
	 if ($(div).style.display=='none') {
		$(div).blindDown({ duration: 1 })
	 }
	 else {
		$(div).blindUp({ duration: 1 })
	}
}

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 loadPage(page)
{ 

	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }
	 
	var url=page;

	xmlHttp.onreadystatechange=function stateChanged() {stateChangedOK2('content',xmlHttp)} 
	xmlHttp.open("GET",url,true)
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=iso-8859-2') 
	xmlHttp.send(null)
			
}

function loadPage2(page, parameters) {
	
	http=GetXmlHttpObject()
	if (http==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }
	 
	var url = page;
	var params = escape(parameters);
	http.open("POST", url, true);
	//Send the proper header information along with the request
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=iso-8859-2') 
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	http.onreadystatechange=function stateChanged() {stateChangedOK2('content',http)} 
	http.send(params);
}

function stateChangedOK2(elementName, httpClass) 
{
	if (httpClass.readyState==4 || httpClass.readyState=="complete")
	 { 
		$(elementName).innerHTML=httpClass.responseText 
	 }
	 else if (httpClass.readyState==3) {
		$(elementName).innerHTML='<center><img src="ajax-loader.gif" alt="Töltés..." /></center>'; 
	 }
	 else if (httpClass.readyState==2) {
		$(elementName).innerHTML='<center><img src="ajax-loader.gif" alt="Töltés..." /></center>'; 
	 }
	 else if (httpClass.readyState==1) {
		$(elementName).innerHTML='<center><img src="ajax-loader.gif" alt="Töltés..." /></center>'; 
	 }


}
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_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_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 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 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"
	url=url+"?city="+city+"&name="+name+"&address="+address+"&pcode="+postalcode+"&tax="+taxnumber+"&orderid="+orderid+"&element="+element

	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 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 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 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)
}

	 