// JavaScript Document
var xmlHttp = createXmlHttpRequestObject(); 

// retrieves the XMLHttpRequest object
function createXmlHttpRequestObject() 
{	
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // if running Internet Explorer
  if(window.ActiveXObject)
  {
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // if running Mozilla or other browsers
  else
  {
    try 
    {
      xmlHttp = new XMLHttpRequest();
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)
 
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}


// make asynchronous HTTP request using the XMLHttpRequest object 


function process(folderpath, pageid, prodid, obj1)
{
  // proceed only if the xmlHttp object isn't busy
 var httpSite="http://www.marginal.dk/";
  
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
	//alert(folderpath + "show_product_xml.php?prodid=" + prodid + "&pageid=" + pageid);  
	
    // retrieve the name typed by the user on the form
    // execute the quickstart.php page from the server
	//alert(folderpath + "show_product_xml.php?prodid=" + prodid + "&pageid=" + pageid+"&obj1=" + obj1); return false;	
    xmlHttp.open("GET", httpSite + folderpath + "show_product_xml.php?prodid=" + prodid + "&pageid=" + pageid+"&obj1=" + obj1, true);  


    // define the method to handle server responses
    xmlHttp.onreadystatechange = handleServerResponse;
    // make the server request
    xmlHttp.send(null);
  } 
}

// executed automatically when a message is received from the server
function handleServerResponse() 
{
  // move forward only if the transaction has completed
  if (xmlHttp.readyState == 4) 
  {
	    
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
	  vcText=document.getElementById('cText');
	  vcImg=document.getElementById('cImg');
      // extract the XML retrieved from the server
      var xmlResponse = xmlHttp.responseXML;
	  
	  if(!xmlResponse || !xmlResponse.documentElement)
	  {
		throw("Invalid XML structure:\n" + xmlHttp.responseText);  
	  }
	  
	  var rootNodeName=xmlResponse.documentElement.nodeName;
	  
	  if(rootNodeName == "parserror")
	  {
		  throw("Invalid XML structure");
	  }
	  
	  xmlRoot=xmlResponse.documentElement;
	  
	  titleArray = xmlRoot.getElementsByTagName("obj1");
	  dateArray = xmlRoot.getElementsByTagName("obj2");
	  idArray = xmlRoot.getElementsByTagName("obj3");	 
	 
      // obtain the document element (the root element) of the XML structure
     
	  
	
	//var txt=xmlDocumentElement.childNodes[1].childNodes[1].nodeValue;
	//var img=xmlDocumentElement.childNodes[3].childNodes[1].nodeValue;
	
	
	  
	  // get the text message, which is in the first child of
      // the the document element
	   
		helloMessage=titleArray.item(0).firstChild.data;
		img=dateArray.item(0).firstChild.data;
		id=idArray.item(0).firstChild.data;

	   //var btn = document.getElementById('btn'+id);	
	   
		x=document.getElementById(id);
		
	
   	     // update the client display using the data received from the server
		 if(helloMessage.length>0)
		 {
	     	vcText.innerHTML = helloMessage;
		 }
		  if(xmlRoot.getElementsByTagName("obj4").item(0).firstChild.data=="img" || xmlRoot.getElementsByTagName("obj4").item(0).firstChild.data=="swf" && (xmlRoot.getElementsByTagName("obj2").item(0).firstChild.data!="flvContinue" && xmlRoot.getElementsByTagName("obj4").item(0).firstChild.data!="flvContinue"))
		  {	 
		 	vcImg.innerHTML = img;
		  }
		 
		  if(xmlRoot.getElementsByTagName("obj4").item(0).firstChild.data==572 || xmlRoot.getElementsByTagName("obj4").item(0).firstChild.data==428)
		  {	  
		 
			wm=xmlRoot.getElementsByTagName("obj4").item(0).firstChild.data;
			wm=parseInt(wm);
		
			
			if(wm==572)
			{
				 vcText.className="shorterText";
				 vcImg.className="widerImg";
			}
			else if(wm==428)
			{
		 		 vcText.className="widerText";
				 vcImg.className="shorterImg";
			}
		  }
		 x.backgroundColor="#ff0000";
		 
		
		 		 
		//alert(document.getElementById('cText'));
		//alert(document.getElementById('cImg'));
	  // restart sequence
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}

