//var hostName = 'http://www.kusa.com.ua';
function show(obj) 
{
	var spanContent = document.getElementById(obj);
	if (spanContent.style.display == 'none') 
	{
		spanContent.style.display = 'block';
	}
	else 
		spanContent.style.display = 'none';
	requestCustomerInfo(obj);	
}

function showSubMenu(obj) 
{
	var id = obj.substring(4);
	var spanContent = document.getElementById(obj);
	if( spanContent )
	{
		var level = '0';
		var className = document.getElementById('menu_'+id).className;
				
		if(className == 'menu' )
			level = '1';
		if(className == 'menuFirst' )
			level = '2';
			
		var arefCont = document.getElementById('aref_'+id);
		
	//	if( !spanContent )
	//	{
	//		spanContent = document.createElement('span');
	//		spanContent.className = 'sub';
	//		spanContent.style.display == 'none';
	//		spanContent.id=obj;
	//		isLoad="0" style="display: none; margin: 0px 0px 0px 20px;"
	//	}
	
		if (spanContent.style.display == 'none') 
		{
			if(spanContent.getAttribute('isLoad') == '0' )
			{
				requestSubMenu(obj, level);
				spanContent.setAttribute('isLoad', '1');
			}
			else
			{
				spanContent.style.display = 'block';
				if (arefCont.firstChild)
					arefCont.firstChild.nodeValue = ' ';
			}		
		}
		else 
		{
			spanContent.style.display = 'none';
			if (arefCont.firstChild)
				arefCont.firstChild.nodeValue = ' ';
		}
	}
//	requestCustomerInfo(obj);	
}

function requestCustomerInfo(obj, modName) {
	
	var oXmlHttp= zXmlHttp.createRequest();
	var id = obj.substring(4);
	if(!modName)
		modName='catalogue_ajax';
	oXmlHttp.open('get',''+hostName+'/'+modName+'/'+id+'?mode=content',true);
//	oXmlHttp.setRequestHeader("Host", "http://globalshop.ua/");
	oXmlHttp.onreadystatechange = function () 
	{
	  if (oXmlHttp.readyState == 4) 
		{
	      if (oXmlHttp.status == 200) {
//	          displayContentInfo(oXmlHttp.getAllResponseHeaders());
						if(modName == 'link')
							id = null;
	          displayContentInfo(parseData(oXmlHttp.responseText,1), id);
	          
	      } else {
	          displayContentInfo("An error occurred: " + oXmlHttp.statusText, null); //statusText is not always accurate
	      }
	  }            
	};
	oXmlHttp.send(null);
}

function displayContentInfo(sText, id) {
	
	var divContent = document.getElementById("divContent");
	if (!divContent)
	{
		//alert ('divContent not found');
		return ;
	}
	
	divContent.innerHTML = sText;
	if( id )
	{
		var spanElemText = document.getElementById("menu_"+id);	
		var content_header = spanElemText.firstChild.nodeValue;		
		var divHeader = document.getElementById("content_header");	
		divHeader.innerHTML = content_header;		
	}
}


function requestSubMenu(obj, level) {
	var oXmlHttp= zXmlHttp.createRequest();
	var id = obj.substring(4);
//http://mivina.com.ua/catalogue_ajax/1?mode=content&level=1
	modName='catalogue_ajax';
	oXmlHttp.open('get',''+hostName+'/'+modName+'/'+id+'?mode=content&level='+level,true);
	
//	oXmlHttp.setRequestHeader("Host", "http://globalshop.ua/");
	oXmlHttp.onreadystatechange = function () 
	{
	  if (oXmlHttp.readyState == 4) 
		{
	      if (oXmlHttp.status == 200) {
//	          displayContentInfo(oXmlHttp.getAllResponseHeaders());
	          displaySubMenu(parseData(oXmlHttp.responseText, 0), id);
//	          displaySubMenu(oXmlHttp.responseText, id);
			//alert(oXmlHttp.responseText);
	      } else {
	          displaySubMenu("An error occurred: " + oXmlHttp.statusText, null); //statusText is not always accurate
	      }
	  }            
	};
	oXmlHttp.send(null);
}

function displaySubMenu(sText, id) {
	var spanContent = document.getElementById("sub_"+id);

	spanContent.innerHTML =   sText;
	spanContent.style.display = 'block';

	var arefCont = document.getElementById('aref_'+id);
	if (arefCont.firstChild)
		arefCont.firstChild.nodeValue = ' ';
}
function parseData(sXml, mode)
{
 	var oXmlDom = zXmlDom.createDocument();
 	var xmlRoot;
  if(!window.opera)
  {
  	oXmlDom.loadXML(sXml);
 	  xmlRoot = oXmlDom.documentElement;
	}
	else
	{
   	var oParser=new DOMParser();
    var oXmlDom=oParser.parseFromString(sXml,"text/xml");
   	xmlRoot = oXmlDom.documentElement;
  }

	var s = new zXMLSerializer();
	var str = '';
		
	if(mode == 1)	
	{
		try{str = xmlRoot.childNodes[1].firstChild.nodeValue}catch(e){str = ''}
		var bigImg = document.getElementById('img_title');
		if( bigImg )
		{
			bigImg.src = str;
		}
	}
	str = s.serialToString(xmlRoot.childNodes[2]);
	return str;
}

/*
function showSubMenu(id) 
{
	var smallImg = document.getElementById('small_img_'+id);
	if( smallImg )
	{
		var bigImg = document.getElementById('img_title');
		if( bigImg )
			bigImg.src = smallImg.src;
	}
}
*/